zoukankan      html  css  js  c++  java
  • MyEclipse +Servlet 乱码

        用MyEclipse 新建了Web Project,然后建立了一个Servlet,在doGet方法中谢了简单的一句欢迎语句,本来以为平平常常的事情,但是却出错了,乱码问题,在网上找了一些帖子,说是设置编码:

    response.setCharacterEncoding("UTF-8"),但是我这里还是不起作用,然后又设置了Header,还是出错,最后将这两句话放在PrintWriter的前面,问题就解决了!
    	public void doGet(HttpServletRequest request, HttpServletResponse response)
    			throws ServletException, IOException {
    
    		response.setCharacterEncoding("UTF-8");
    		//解决不了,后来又搜到一条解决方法是:
    		response.setHeader("content-type","text/html;charset=UTF-8");
    		PrintWriter out = response.getWriter();
    		String sName = "";
    		if(request.getParameterNames().hasMoreElements())
    		{
    			sName=request.getParameter("name");
    		}
    		
    		
    		//response.setContentType("text/html;charset=utf-8");
    
              out.println("<html><body>");
              out.println("您好:"+sName+"!");
              out.println("</body></html>");
              
              out.close();
    	}
    

      

  • 相关阅读:
    前缀和
    hdu6290奢侈的旅行
    make_pair
    New Year and Buggy Bot
    STL next_permutation 算法原理和自行实现
    前端面试题集合
    node设置cookie
    黑客与geek
    xss
    node async
  • 原文地址:https://www.cnblogs.com/zuiyirenjian/p/3967465.html
Copyright © 2011-2022 走看看