本文整理汇总了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());
}
}
}