當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServletResponse.setContentType方法代碼示例

本文整理匯總了Java中javax.servlet.http.HttpServletResponse.setContentType方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletResponse.setContentType方法的具體用法?Java HttpServletResponse.setContentType怎麽用?Java HttpServletResponse.setContentType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.http.HttpServletResponse的用法示例。


在下文中一共展示了HttpServletResponse.setContentType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: downloadSignedFile

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@RequestMapping(value = "/download", method = RequestMethod.GET)
public String downloadSignedFile(@ModelAttribute("signedDocument") InMemoryDocument signedDocument, HttpServletResponse response) {
	try {
		MimeType mimeType = signedDocument.getMimeType();
		if (mimeType != null) {
			response.setContentType(mimeType.getMimeTypeString());
		}
		response.setHeader("Content-Transfer-Encoding", "binary");
		response.setHeader("Content-Disposition", "attachment; filename=\"" + signedDocument.getName() + "\"");
		Utils.copy(new ByteArrayInputStream(signedDocument.getBytes()), response.getOutputStream());

	} catch (Exception e) {
		logger.error("An error occured while pushing file in response : " + e.getMessage(), e);
	}
	return null;
}
 
開發者ID:esig,項目名稱:dss-demonstrations,代碼行數:17,代碼來源:SignatureController.java

示例2: execute

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String method=retriveMethod(req);
	if(method!=null){
		invokeMethod(method, req, resp);
	}else{
		VelocityContext context = new VelocityContext();
		context.put("contextPath", req.getContextPath());
		String file=req.getParameter("file");
		String project = buildProjectNameFromFile(file);
		if(project!=null){
			context.put("project", project);
		}
		resp.setContentType("text/html");
		resp.setCharacterEncoding("utf-8");
		Template template=ve.getTemplate("html/decisiontable-editor.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:22,代碼來源:DecisiontableEditorServletHandler.java

示例3: 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

示例4: createSuccessResponse

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
public static String createSuccessResponse(Integer httpCode, Object result, SerializerFeature serializerFeature, SerializeFilter filter, HttpServletResponse response){
		PrintWriter printWriter = null;
		String jsonString = "";
		try {
			response.setCharacterEncoding(RESPONSE_CHARACTERENCODING);
			response.setContentType(RESPONSE_CONTENTTYPE);
			response.setStatus(httpCode);
			printWriter = response.getWriter();
			if(null != result){
				if(null!=filter){
					jsonString = JSONObject.toJSONString(result,filter,serializerFeature);
				}else{
//					jsonString = JSONObject.toJSONString(result, serializerFeature);
					jsonString = JSONObject.toJSONStringWithDateFormat(result,"yyyy-MM-dd HH:ss:mm",serializerFeature);
				}
				printWriter.write(jsonString); 
			}
			printWriter.flush();

		} catch (Exception e) {
			log.error("createResponse failed", e);
		} finally {
			if(null!=printWriter)printWriter.close();
		}
		return jsonString;
	}
 
開發者ID:leon66666,項目名稱:spring-boot-frameset,代碼行數:27,代碼來源:ServletUtil.java

示例5: getText1

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@RequestMapping("/text1")
public void getText1(HttpServletRequest request, HttpServletResponse response, ModelMap model) {
	try {
		response.setContentType("text/html;charset=UTF-8");
		response.getWriter().write("hello");
	} catch (IOException e) {
		logger.error("getText1 error:", e);
	}
}
 
開發者ID:wz12406,項目名稱:accumulate,代碼行數:10,代碼來源:TestController.java

示例6: doPost

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	// TODO Auto-generated method stub
	System.out.println("DISCONNECT PAIR SERVLET");
	String pairId=request.getParameter("pairId");
//	String nextPage=request.getParameter("jsp");
	int id=Integer.parseInt(pairId);
	
	DataAccess da = new DataAccess();
    boolean res=true;
    RequestDispatcher req = null;
    response.setContentType("text/html");
    
	res = da.disconnectPair(id);
	
	try {
		da.closeConnection();
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	if(res){
	//	response.getWriter().append("Disconnect Pair Successfull");
		
		response.getWriter().append(""+id);
		//req = request.getRequestDispatcher(nextPage);
	}
	else 
		//response.getWriter().append("Disconnect Pair Is Failure");
	
	req.forward(request, response);
	
}
 
開發者ID:shalomweiss,項目名稱:mm-system-2017,代碼行數:37,代碼來源:DisconnectPair.java

示例7: doGet

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
     * Method declaration
     *
     *
     * @param request
     * @param response
     *
     * @throws IOException
     * @throws ServletException
     */
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
                      throws IOException, ServletException {

        String query = request.getQueryString();

        if ((query == null) || (query.length() == 0)) {
            response.setContentType("text/html");

// [email protected] 20020130 - patch 1.7.0 by fredt
// to avoid caching on the browser
            response.setHeader("Pragma", "no-cache");

            PrintWriter out = response.getWriter();

            out.println(
                "<html><head><title>HSQL Database Engine Servlet</title>");
            out.println("</head><body><h1>HSQL Database Engine Servlet</h1>");
            out.println("The servlet is running.<p>");

            if (errorStr == null) {
                out.println("The database is also running.<p>");
                out.println("Database name: " + dbType + dbPath + "<p>");
                out.println("Queries processed: " + iQueries + "<p>");
            } else {
                out.println("<h2>The database is not running!</h2>");
                out.println("The error message is:<p>");
                out.println(errorStr);
            }

            out.println("</body></html>");
        }
    }
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:44,代碼來源:Servlet.java

示例8: doGet

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    resp.setContentType("text/plain");
    resp.getWriter().print("envEntry1: " + envEntry1);
    resp.getWriter().print(" envEntry2: " + envEntry2);
    resp.getWriter().print(" envEntry3: " + envEntry3);
    resp.getWriter().print(" envEntry4: " + envEntry4);
    resp.getWriter().print(" envEntry5: " + envEntry5);
    resp.getWriter().print(" envEntry6: " + envEntry6);
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:12,代碼來源:TesterServletWithAnnotations.java

示例9: processPendingResponses

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
synchronized void processPendingResponses(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    JSONArray responses = new JSONArray();
    JSONStreamAware pendingResponse;
    while ((pendingResponse = pendingResponses.poll()) != null) {
        responses.add(pendingResponse);
    }
    if (responses.size() > 0) {
        JSONObject combinedResponse = new JSONObject();
        combinedResponse.put("responses", responses);
        if (asyncContext != null) {
            asyncContext.getResponse().setContentType("text/plain; charset=UTF-8");
            try (Writer writer = asyncContext.getResponse().getWriter()) {
                combinedResponse.writeJSONString(writer);
            }
            asyncContext.complete();
            asyncContext = req.startAsync();
            asyncContext.addListener(new UserAsyncListener());
            asyncContext.setTimeout(5000);
        } else {
            resp.setContentType("text/plain; charset=UTF-8");
            try (Writer writer = resp.getWriter()) {
                combinedResponse.writeJSONString(writer);
            }
        }
    } else {
        if (asyncContext != null) {
            asyncContext.getResponse().setContentType("text/plain; charset=UTF-8");
            try (Writer writer = asyncContext.getResponse().getWriter()) {
                JSON.emptyJSON.writeJSONString(writer);
            }
            asyncContext.complete();
        }
        asyncContext = req.startAsync();
        asyncContext.addListener(new UserAsyncListener());
        asyncContext.setTimeout(5000);
    }
}
 
開發者ID:muhatzg,項目名稱:burstcoin,代碼行數:38,代碼來源:User.java

示例10: processRequest

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    DAOTipoMoeda daoTipoMoeda = null;
    TipoMoeda tipoMoeda = null;
    RequestDispatcher view = null;
    String msg = null;
    String tipoMsg = "success";

    try {
        daoTipoMoeda = new DAOTipoMoeda();
        tipoMoeda = new TipoMoeda();

        tipoMoeda.setNome(request.getParameter("txtNome"));
        tipoMoeda.setSimbolo(request.getParameter("txtSimbolo"));

        ArrayList<TipoMoeda> lista = daoTipoMoeda.consultar(tipoMoeda);

        request.setAttribute("al", lista);                                    
    } catch (Exception exception) {
        tipoMsg = "danger";
        msg = exception.getMessage();            

    } finally {
        view = request.getRequestDispatcher("/pages/tipoMoedaConsultar.jsp");
        request.setAttribute("mensagem", msg);
        request.setAttribute("tipoMsg", tipoMsg);
        view.forward(request, response);
    }
}
 
開發者ID:deivisvieira,項目名稱:PosJava,代碼行數:41,代碼來源:ControleTipoMoedaConsultar.java

示例11: onLogoutSuccess

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
  public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse response, Authentication authentication)
          throws IOException, ServletException {
      Map<String, String> result = new HashMap<>();
      result.put( "result", "success" );
response.setContentType("application/json");
response.getWriter().write( objectMapper.writeValueAsString( result ) );
      response.setStatus(HttpServletResponse.SC_OK);

  }
 
開發者ID:bfwg,項目名稱:angular-spring-starter,代碼行數:11,代碼來源:LogoutSuccess.java

示例12: writeAJAXResponse

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
protected void writeAJAXResponse(HttpServletResponse response, String output) throws IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();

if (output.length() > 0) {
    out.println(output);
}

out.flush();
out.close();
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:12,代碼來源:RegisterAction.java

示例13: processRequest

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * Processes requests for both HTTP
 * <code>GET</code> and
 * <code>POST</code> methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
        if(sc==null)
       {
           sc = getServletConfig();
            if(sc!=null) init(sc);
       }
    

        Map<String, String> __params = new HashMap<String, String>();
        Enumeration __e = request.getParameterNames();
        while (__e.hasMoreElements()) {
            String tField = __e.nextElement().toString();
            __params.put(tField, request.getParameter(tField));
        }
        __params.put("contextpath", request.getContextPath());
        String __result=getResponce(__params);
        out.println(__result);
    } finally {  
        out.flush();
        out.close();
    }
}
 
開發者ID:dimasalomatine,項目名稱:sdirobot,代碼行數:37,代碼來源:Enter.java

示例14: wapPay

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * Wap支付
 * https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.dfHHR3&
 * treeId=203&articleId=105285&docType=1
 * 
 * @throws AlipayApiException
 * @throws IOException
 */
public static void wapPay(HttpServletResponse response, AlipayTradeWapPayModel model, String returnUrl,
		String notifyUrl) throws AlipayApiException, IOException {
	String form = wapPayToString(response, model, returnUrl, notifyUrl);
	HttpServletResponse httpResponse = response;
	httpResponse.setContentType("text/html;charset=" + AliPayConfig.build().getCharset());
	httpResponse.getWriter().write(form);// 直接將完整的表單html輸出到頁麵
	httpResponse.getWriter().flush();
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:17,代碼來源:AliPay.java

示例15: ajaxPolling

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * Ajax輪詢
 * @param response    HttpServletResponse
 * @param requestTime 開始請求時間
 * @throws Exception
 */
@RequestMapping(value="/ajax/polling", method= RequestMethod.GET)
public void ajaxPolling(HttpServletResponse response,long requestTime) throws Exception{
    response.setContentType("text/html;charset=utf-8");
    PrintWriter writer = response.getWriter();
    Thread.sleep(new Random().nextInt(1000)); //模擬業務處理時間
    int num = new Random().nextInt(100); //模擬查詢到的數據,查到就返回
    long responseTime = System.currentTimeMillis();
    if(num >10 && num <50){ //有數據變化
        writer.print(String.format("response time: %s,  request time: %s, result: %d", responseTime,requestTime,num));
    }else{ //無數據變化
        writer.print(String.format("response time: %s,  request time: %s, result: %s", responseTime,requestTime,"無數據變化"));
    }
}
 
開發者ID:chang20159,項目名稱:Instant-Messaging,代碼行數:20,代碼來源:PollingController.java


注:本文中的javax.servlet.http.HttpServletResponse.setContentType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。