当前位置: 首页>>代码示例>>Java>>正文


Java HttpServletResponse.addHeader方法代码示例

本文整理汇总了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);
}
 
开发者ID:PestaKit,项目名称:microservice-email,代码行数:10,代码来源:ApiOriginFilter.java

示例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());
}
 
开发者ID:myliang,项目名称:fish-admin,代码行数:19,代码来源:UsersController.java

示例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;
		}
	}
 
开发者ID:ferenc-hechler,项目名称:RollenspielAlexaSkill,代码行数:34,代码来源:HealthCheckServlet.java

示例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());
    }
}
 
开发者ID:mkopylec,项目名称:errorest-spring-boot-starter,代码行数:9,代码来源:ErrorsHttpResponseSetter.java

示例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());  
}
 
开发者ID:gyp220203,项目名称:renren-msg,代码行数:22,代码来源:SysGeneratorController.java

示例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);
}
 
开发者ID:wengwh,项目名称:plumdo-work,代码行数:14,代码来源:CorsFilterConfiguration.java

示例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");

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:22,代码来源:WebdavServlet.java

示例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");
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:15,代码来源:ExportServlet.java

示例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);
}
 
开发者ID:cliffano,项目名称:swaggy-jenkins,代码行数:9,代码来源:ApiOriginFilter.java

示例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");

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:11,代码来源:NoCachePhaseListener.java

示例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;
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:31,代码来源:HealthCheckController.java

示例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;
}
 
开发者ID:spring-cloud-samples,项目名称:sample-zuul-filters,代码行数:8,代码来源:AddResponseHeaderFilter.java

示例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);
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:11,代码来源:ClearCacheFilter.java

示例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();
}
 
开发者ID:ZHENFENG13,项目名称:ssm-demo,代码行数:9,代码来源:ResponseUtil.java

示例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());
    	}
    }
  	
  }
 
开发者ID:stppy,项目名称:spr,代码行数:46,代码来源:ajaxSelectsHacienda.java


注:本文中的javax.servlet.http.HttpServletResponse.addHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。