当前位置: 首页>>代码示例>>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;未经允许,请勿转载。