本文整理匯總了Java中javax.servlet.http.HttpServletResponse.addHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletResponse.addHeader方法的具體用法?Java HttpServletResponse.addHeader怎麽用?Java HttpServletResponse.addHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.servlet.http.HttpServletResponse
的用法示例。
在下文中一共展示了HttpServletResponse.addHeader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doFilter
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletResponse res = (HttpServletResponse) response;
res.addHeader("Access-Control-Allow-Origin", "*");
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
chain.doFilter(request, response);
}
示例2: index
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@GetMapping({"", "/"})
@PreAuthorize("hasPermission('User', 'read')")
public List index(HttpServletRequest request, HttpServletResponse response) {
Pagination<User> page = userRepository.where(SqlQuery.build(request).like("userName").eq("state"));
response.addHeader("x-total-count", page.getTotal() + "");
return page.getContent().stream().map((item) -> {
// get role
Role role = roleRepository.find(item.getRoleId());
Map<String, Object> ret = new HashMap();
ret.put("id", item.getId());
ret.put("roleId", item.getRoleId());
ret.put("userName", item.getUserName());
ret.put("state", item.getState());
ret.put("roleName", role != null ? role.getName() : "");
ret.put("createdAt", item.getCreatedAt());
return ret;
}).collect(Collectors.toList());
}
示例3: doPost
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
response.setHeader("Pragma", "no-cache");
// logger.info("encoding : " + response.getCharacterEncoding());
PrintWriter writer = response.getWriter();
String ibookDbStatus = getDbStatus();
String html = "<html><body><table border='1'>"
+ "<tr><th>Object</th><th>Status</th></tr>"
+ "<tr><td>Solo-DB</td><td>"+ibookDbStatus+"</td></tr>"
+ "</table></body></html>";
writer.println(html);
boolean ok = "OK".equals(ibookDbStatus);
if (!ok) {
response.setStatus(500);
}
}
catch (RuntimeException | IOException e) {
logger.log(Level.SEVERE, "RQ[HEALT] -> "+e.toString(), e);
throw e;
}
}
示例4: setErrorsResponse
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
public void setErrorsResponse(Errors errors, HttpStatus responseHttpStatus, HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setStatus(responseHttpStatus.value());
HttpResponseData responseData = getResponseData(errors, request);
if (responseData != null) {
response.addHeader(CONTENT_TYPE, responseData.getContentType());
response.getWriter().write(responseData.getBody());
}
}
示例5: code
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
* 生成代碼
*/
@RequestMapping("/code")
@RequiresPermissions("sys:generator:code")
public void code(HttpServletRequest request, HttpServletResponse response) throws IOException{
String[] tableNames = new String[]{};
//獲取表名,不進行xss過濾
HttpServletRequest orgRequest = XssHttpServletRequestWrapper.getOrgRequest(request);
String tables = orgRequest.getParameter("tables");
tableNames = JSON.parseArray(tables).toArray(tableNames);
byte[] data = sysGeneratorService.generatorCode(tableNames);
response.reset();
response.setHeader("Content-Disposition", "attachment; filename=\"renren.zip\"");
response.addHeader("Content-Length", "" + data.length);
response.setContentType("application/octet-stream; charset=UTF-8");
IOUtils.write(data, response.getOutputStream());
}
示例6: doFilterInternal
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
// Access-Control-Allow-Origin: 指定授權訪問的域
response.addHeader("Access-Control-Allow-Origin", "*"); //此優先級高於@CrossOrigin配置
// Access-Control-Allow-Methods: 授權請求的方法(GET, POST, PUT, DELETE,OPTIONS等)
response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
response.addHeader("Access-Control-Allow-Headers", "Content-Type");
response.addHeader("Access-Control-Max-Age", "1800");//30 min
filterChain.doFilter(request, response);
}
示例7: doOptions
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
* OPTIONS Method.
*
* @param req The request
* @param resp The response
* @throws ServletException If an error occurs
* @throws IOException If an IO error occurs
*/
@Override
protected void doOptions(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.addHeader("DAV", "1,2");
StringBuilder methodsAllowed = determineMethodsAllowed(resources,
req);
resp.addHeader("Allow", methodsAllowed.toString());
resp.addHeader("MS-Author-Via", "DAV");
}
示例8: sendCSVFile
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
private void sendCSVFile(String csv, String filename, HttpServletResponse resp)
throws IOException {
xLogger.fine("Entered sendCSVFile");
if (csv == null) {
return;
}
resp.setCharacterEncoding("UTF-8");
resp.setContentType("text/csv");
resp.addHeader("Content-Disposition", "inline; filename=" + filename);
PrintWriter pw = resp.getWriter();
pw.write(csv);
pw.close();
xLogger.fine("Exiting sendCSVFile");
}
示例9: doFilter
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletResponse res = (HttpServletResponse) response;
res.addHeader("Access-Control-Allow-Origin", "*");
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
chain.doFilter(request, response);
}
示例10: beforePhase
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
public void beforePhase(PhaseEvent phaseEvent) {
FacesContext facesContext = phaseEvent.getFacesContext();
HttpServletResponse response = (HttpServletResponse) facesContext
.getExternalContext().getResponse();
response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-Control", "no-cache,no-store,must-revalidate");
response.addHeader("Expires", "0");
}
示例11: handleRequestInternal
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(
final HttpServletRequest request, final HttpServletResponse response)
throws Exception {
final HealthStatus healthStatus = this.healthCheckMonitor.observe();
final StringBuilder sb = new StringBuilder();
sb.append("Health: ").append(healthStatus.getCode());
String name;
Status status;
int i = 0;
for (final Map.Entry<String, Status> entry : healthStatus.getDetails().entrySet()) {
name = entry.getKey();
status = entry.getValue();
response.addHeader("X-CAS-" + name, String.format("%s;%s", status.getCode(), status.getDescription()));
sb.append("\n\n\t").append(++i).append('.').append(name).append(": ");
sb.append(status.getCode());
if (status.getDescription() != null) {
sb.append(" - ").append(status.getDescription());
}
}
response.setStatus(healthStatus.getCode().value());
response.setContentType("text/plain");
response.getOutputStream().write(sb.toString().getBytes(response.getCharacterEncoding()));
// Return null to signal MVC framework that we handled response directly
return null;
}
示例12: run
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
public Object run() {
RequestContext context = RequestContext.getCurrentContext();
HttpServletResponse servletResponse = context.getResponse();
servletResponse.addHeader("X-Foo",
UUID.randomUUID().toString());
return null;
}
示例13: doFilter
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
HttpServletResponse response = (HttpServletResponse) resp;
response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-Control", "no-cache, no-store, max-age=0");
response.addDateHeader("Expires", 1L);
chain.doFilter(req, resp);
}
示例14: write
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
public static void write(HttpServletResponse response, Object o) throws Exception {
response.setContentType("text/html;charset=utf-8");
response.addHeader("Access-Control-Allow-Origin", "*");
PrintWriter out = response.getWriter();
out.println(o.toString());
out.flush();
out.close();
}
示例15: doPost
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String accion = request.getParameter("accion");
Integer anho=null;
Integer version=null;
Integer pais=null;
if (request.getParameter("anho")!=null) anho = Integer.parseInt(request.getParameter("anho")); else anho=0;
if (request.getParameter("version")!=null) version = Integer.parseInt(request.getParameter("version")); else version=0;
if (request.getParameter("pais")!=null) pais = Integer.parseInt(request.getParameter("pais")); else pais=1;
PrintWriter out = response.getWriter();
response.setContentType("text/html");
response.setHeader("Cache-control", "no-cache, no-store");
response.setHeader("Pragma", "no-cache");
response.setHeader("Expires", "-1");
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST");
response.addHeader("Access-Control-Allow-Origin","*");
response.addHeader("Access-Control-Allow-Methods","GET,POST");
response.addHeader("Access-Control-Allow-Headers","Origin, X-Requested-With, Content-Type, Accept");
response.setHeader("Access-Control-Allow-Headers", "Content-Type");
response.setHeader("Access-Control-Max-Age", "1");
if ( request.getMethod().equals("OPTIONS") ) {
response.setStatus(HttpServletResponse.SC_OK);
return;
}
Gson gson = new Gson();
JsonObject myObj = new JsonObject();
String callback = request.getParameter("callback");
if (accion!=null && accion!=""){
if (accion.equals("getUnidadMedida")){
List objetos = Client.getUnidadesDeMedida();
JsonElement json = new Gson().toJsonTree(objetos );
myObj.addProperty("success", true);
myObj.add("unidad_medida", json);
out.println(myObj.toString());
}
}
}