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


Java HttpServletResponse.setCharacterEncoding方法代码示例

本文整理汇总了Java中javax.servlet.http.HttpServletResponse.setCharacterEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletResponse.setCharacterEncoding方法的具体用法?Java HttpServletResponse.setCharacterEncoding怎么用?Java HttpServletResponse.setCharacterEncoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.http.HttpServletResponse的用法示例。


在下文中一共展示了HttpServletResponse.setCharacterEncoding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doPost

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override          
     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
     {
             response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
response.setBufferSize(8192);
             
             switch (Integer.parseInt(request.getParameter("case")))
             {
                  case 1 :  getServletContext().getRequestDispatcher("/entryreview.jsp").forward(request,response);  
                            return;
                  case 2 :  getServletContext().getRequestDispatcher("/place_entry.jsp").forward(request,response);
                            return;
                  case 3 :  getServletContext().getRequestDispatcher("/updatemobno.jsp").forward(request,response);
                            return;
                  case 4 :  getServletContext().getRequestDispatcher("/updatepassword.jsp").forward(request,response);
                            return;
                  case 5 :  getServletContext().getRequestDispatcher("/updateemail.jsp").forward(request,response);
                            return;
                  default : request.setAttribute("uid", request.getParameter("uid"));
                            getServletContext().getRequestDispatcher("/successlogin.jsp").forward(request,response);
                            return;
             }
     }
 
开发者ID:Tejas07PSK,项目名称:EBwn2_ForOpenShift,代码行数:25,代码来源:SchUtil.java

示例2: page

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
public void page(HttpServletResponse response, int statusCode, String title, String message) throws IOException {
    title = htmlEncode(title);
    message = htmlEncode(message);
    response.setContentType("text/html");
    response.setCharacterEncoding("utf-8");
    PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF-8"));
    out.println("<html>");
    out.println("<head><title>" + title + "</title></head>");
    out.println("<body>");
    out.println("<h2>" + title + "</h2>");
    out.println("<p>" + message + "</p>");
    out.println("</body>");
    out.println("</html>");
    out.flush();
    response.setStatus(statusCode);
}
 
开发者ID:yifangyun,项目名称:fangcloud-java-sdk,代码行数:17,代码来源:Common.java

示例3: render

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
private static void render(HttpServletResponse response, String text) {
    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0L);
    PrintWriter pw = null;

    try{
        pw = response.getWriter();
        pw.write(text);
    } catch (IOException var8) {
        var8.printStackTrace();
    } finally {
        pw.close();
    }

}
 
开发者ID:BetaSummer,项目名称:sztw,代码行数:18,代码来源:BaseController.java

示例4: queryUserByPost

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
 * @note 获取岗位下的所有用户
 * @param postId 岗位ID
 * @return IUser[]
 */
@RequestMapping("/queryUserByPost")
public void queryUserByPost(HttpServletRequest request, HttpServletResponse response)
{
	MyRequest req = new MyRequest(request);
	String systemAlias = req.getString("name");
	String pwd = req.getString("pwd");
	String postId = req.getString("postId");
	try
	{
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/plain;charset=UTF-8");
		PrintWriter out = response.getWriter();
		if(isSystemCheck(systemAlias, pwd))
		{
			IUser[] m = service.queryUserByPostid(postId);
			out.print(toJson(m));
		}
		out.print("");
	}
	catch(Exception ex)
	{
		ex.printStackTrace();
	}
}
 
开发者ID:skeychen,项目名称:dswork,代码行数:30,代码来源:APIController.java

示例5: popupQrImageUpdateSubmit

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
 * 通用电脑模式,更改底部的二维码,提交保存
 */
@RequestMapping(value = "popupQrImageUpdateSubmit")
public void popupQrImageUpdateSubmit(Model model,HttpServletRequest request,HttpServletResponse response,
		@RequestParam("qrImageFile") MultipartFile multipartFile) throws IOException{
	JSONObject json = new JSONObject();
	Site site = getSite();
	
	if(!(multipartFile.getContentType().equals("image/pjpeg") || multipartFile.getContentType().equals("image/jpeg") || multipartFile.getContentType().equals("image/png") || multipartFile.getContentType().equals("image/gif"))){
		json.put("result", "0");
		json.put("info", "请传入jpg、png、gif格式的二维码图");
	}else{
		//格式转换
		BufferedImage bufferedImage = ImageUtil.inputStreamToBufferedImage(multipartFile.getInputStream());
        BufferedImage tag = ImageUtil.formatConversion(bufferedImage);
        BufferedImage tag1 = ImageUtil.proportionZoom(tag, 400);
		
		//上传
        AttachmentFile.put("site/"+site.getId()+"/images/qr.jpg", ImageUtil.bufferedImageToInputStream(tag1, "jpg"));
		
		AliyunLog.addActionLog(getSiteId(), "通用电脑模式,更改底部的二维码,提交保存");
		
		json.put("result", "1");
	}
	
	response.setCharacterEncoding("UTF-8");  
    response.setContentType("application/json; charset=utf-8");  
    PrintWriter out = null;  
    try {  
        out = response.getWriter();  
        out.append(json.toString());
    } catch (IOException e) {  
        e.printStackTrace();  
    } finally {  
        if (out != null) {  
            out.close();  
        }  
    }  
}
 
开发者ID:xnx3,项目名称:wangmarket,代码行数:41,代码来源:SiteController.java

示例6: run

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
public void run(String serviceName, HttpServletRequest request, HttpServletResponse response) throws ServiceException {
       try {
		// Create the document XML response
           Document document = DOMUtils.createDocument();
           Element adminElement = document.createElement("admin");
           adminElement.setAttribute("service", serviceName);
           document.appendChild(adminElement);
		
           // Run the core service
           getServiceResult(request, document);

           // Update servlet response and write result
   		response.setContentType(MimeType.TextXml.value());
		response.setCharacterEncoding("UTF-8");
		Writer writer = response.getWriter();
		XMLUtils.prettyPrintDOMWithEncoding(document, "UTF-8", writer);

		if (Engine.logAdmin.isDebugEnabled()) {
			String xml = XMLUtils.prettyPrintDOM(document);
			Engine.logAdmin.debug("XML generated:\n" + xml);
		}
       }
    catch (Throwable t) {
		ServiceUtils.handleError(t, response);
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:27,代码来源:XmlService.java

示例7: getAllTaskFinished

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
 * 得到完成未完成的图片任务
 * 
 * @param response
 * @param request
 * @throws IOException
 */
@RequestMapping(value = "/admin/getalltaskfinished", method = RequestMethod.POST)
public void getAllTaskFinished(HttpServletResponse response, HttpServletRequest request) throws IOException {

	request.setCharacterEncoding("utf-8");
	response.setCharacterEncoding("utf-8"); // 设置响应responce编码为utf-8
	PrintWriter out = response.getWriter();
	String json;
	Gson gson = new Gson();
	AssignImageLabel assign = new AssignImageLabel();

	long unfinishedAmount = imageService.getAmountOfDefinedImage(0);
	long finishedAmount = imageService.getAmountOfDefinedImage(1);

	assign.setAll_img_amount((unfinishedAmount + finishedAmount) + "");
	assign.setFinished_img(finishedAmount + "");
	assign.setUnfinished_img(unfinishedAmount + "");
	Message<AssignImageLabel> message = new Message<AssignImageLabel>("200", "", assign);// 初始化message对象
	json = gson.toJson(message, Message.class); // 使用gson将Message对象转化为字符串
	out.print(json);
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:28,代码来源:AdminController.java

示例8: 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/ul-editor.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
开发者ID:youseries,项目名称:urule,代码行数:22,代码来源:ULEditorServletHandler.java

示例9: setLocale

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
    * Returns the serialized XML of the Mindmap Nodes from Database
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return null
    */
   public ActionForward setLocale(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) {

try {
    response.setContentType("text/xml");
    response.setCharacterEncoding("utf-8");
    response.getWriter().write(mindmapService.getLanguageXML());
} catch (IOException e) {
    e.printStackTrace();
}

return null;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:MonitoringAction.java

示例10: doPost

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
 * Passes a POST request to the dispatcher.
 * 
 * @throws IOException
 *             if an input or output error is detected when the servlet
 *             handles the request
 * @throws ServletException
 *             if the request for the POST could not be handled
 */
@Override
protected void doPost(final HttpServletRequest request,
		final HttpServletResponse response) throws ServletException,
		IOException {
	request.setCharacterEncoding("UTF-8");
	response.setCharacterEncoding("UTF-8");
	response.setContentType("text/html");
	response.setHeader("Cache-Control", "no-cache");
	PrintWriter out = response.getWriter();
	UploadResponse uploadResponse = null;

	try {
		ThreadLocalData.beginRequest(request);
		uploadResponse = dispatcher.doPost(request);
	} catch (Exception e) {
		throw new ServletException(e);
	} finally {
		/*
		 * call this method to prevent detached requests or else the request
		 * will probably never be garbage collected and will fill your
		 * memory
		 */
		ThreadLocalData.endRequest();
	}

	out.print(uploadResponse);
	out.flush();
	out.close();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:39,代码来源:ConnectorServlet.java

示例11: doFilter

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
	HttpServletRequest req = (HttpServletRequest) request;
	HttpServletResponse res = (HttpServletResponse) response;
	req.setCharacterEncoding(this.encoding);
	if (this.forceEncoding) {
		res.setCharacterEncoding(this.encoding);
	}
	chain.doFilter(req, res);
}
 
开发者ID:skeychen,项目名称:dswork,代码行数:11,代码来源:CharacterEncodingFilter.java

示例12: doFilter

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest req, ServletResponse resp,
		FilterChain filterChain) throws IOException, ServletException {
	//如果没有验证通过,那么就把请求转发到login.html
	HttpServletResponse httpServletResponse = (HttpServletResponse) resp;
	HttpServletRequest httpServletRequest = (HttpServletRequest) req;
	
	httpServletRequest.setCharacterEncoding("UTF-8");
	httpServletResponse.setCharacterEncoding("UTF-8");
	
	switch(httpServletRequest.getRequestURI()){
		case "/":
			if(AuthConfig.isContinueLockMain()){
				httpServletResponse.sendRedirect("/login.html");
			}else{
				httpServletResponse.sendRedirect("/index.html");
			}
			break;
		case "/index.html":
			if(AuthConfig.isContinueLockMain()){
				httpServletResponse.sendRedirect("/login.html");
			}else{
				filterChain.doFilter(httpServletRequest, httpServletResponse);
			}
			break;
		default:
			filterChain.doFilter(httpServletRequest, httpServletResponse);
	}
}
 
开发者ID:GroupControlDroid,项目名称:GroupControlDroidClient,代码行数:30,代码来源:CommonFilter.java

示例13: cpu

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@RequestMapping("/cpu")
@ResponseBody
public void cpu(HttpServletResponse response) throws IOException {
    String aa = JMXClient.getInstance().getCpuUsage();
    response.setCharacterEncoding("UTF-8");
    response.setContentType("text/html;charset=UTF-8");
    response.getWriter().write(aa);
}
 
开发者ID:Zephery,项目名称:newblog,代码行数:9,代码来源:LogController.java

示例14: writeResponse

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
public void writeResponse(HttpServletRequest request, HttpServletResponse httpResponse, Response jaxbResponse) {

        String format = getStringParameter(request, "f", "xml");
        String jsonpCallback = request.getParameter("callback");
        boolean json = "json".equals(format);
        boolean jsonp = "jsonp".equals(format) && jsonpCallback != null;
        Marshaller marshaller;

        if (json) {
            marshaller = createJsonMarshaller();
            httpResponse.setContentType("application/json");
        } else if (jsonp) {
            marshaller = createJsonMarshaller();
            httpResponse.setContentType("text/javascript");
        } else {
            marshaller = createXmlMarshaller();
            httpResponse.setContentType("text/xml");
        }

        httpResponse.setCharacterEncoding(StringUtil.ENCODING_UTF8);

        try {
            StringWriter writer = new StringWriter();
            if (jsonp) {
                writer.append(jsonpCallback).append('(');
            }
            marshaller.marshal(new ObjectFactory().createSubsonicResponse(jaxbResponse), writer);
            if (jsonp) {
                writer.append(");");
            }
            httpResponse.getWriter().append(writer.getBuffer());
        } catch (JAXBException | IOException x) {
            LOG.error("Failed to marshal JAXB", x);
            throw new RuntimeException(x);
        }
    }
 
开发者ID:airsonic,项目名称:airsonic,代码行数:37,代码来源:JAXBWriter.java

示例15: doPost

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setCharacterEncoding("UTF-8");
    req.setCharacterEncoding("UTF-8");
    getHeadersInfo(req);
    routeByHeader(req);
    String retJson = "hello i'm running... server time: " + TimeUtil.msec2date(System.currentTimeMillis()) + " ,version " + Params.versionName;
    PrintWriter writer = resp.getWriter();
    writer.write(retJson);
    writer.flush();
    writer.close();
}
 
开发者ID:lucid-lynxz,项目名称:Webhook_server,代码行数:13,代码来源:ApiServlet.java


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