當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。