Xhiu_huang 2016-12-11 09:08 采纳率: 0%
浏览 1491

servlet中文显示乱码问题

运行时显示乱码,试了n多方法还是不行,myeclipse里边jsp什么的设置的是utf-8。求大神解答
package servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**

  • Servlet implementation class firstServlet
    */
    public class firstServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**

    • @see HttpServlet#HttpServlet() */ public firstServlet() { super(); // TODO Auto-generated constructor stub }

    /**

    • @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
      */
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
      request.setCharacterEncoding("UTF-8");

      PrintWriter out = response.getWriter();
      response.setCharacterEncoding("UTF-8");
      response.setContentType("text/html,charest=UTF-8");

      out.write("获取到的客户机信息如下:");
      out.write("
      ");
      out.write("请求的url地址:"+request.getRequestURL());
      out.write("
      ");
      out.write("请求的资源:"+request.getRequestURI());
      out.write("
      ");
      out.write("请求的URL地址中附带的参数:"+request.getQueryString());
      out.write("
      ");
      out.write("来访者的IP地址:"+request.getRemoteAddr());
      out.write("
      ");
      out.write("来访者的主机名:"+request.getRemoteHost());
      out.write("
      ");
      out.write("使用的端口号:"+request.getRemotePort());
      out.write("
      ");
      out.write("remoteUser"+request.getRemoteUser());
      out.write("
      ");
      out.write("请求使用的方法:"+request.getMethod());
      out.write("
      ");
      out.write("pathInfo:"+request.getPathInfo());
      out.write("
      ");
      out.write("localAddr:"+request.getLocalAddr());
      out.write("
      ");
      out.write("localName:"+request.getLocalName());
      out.write("
      ");
      out.close();
      }
      /**

    • @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
      */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // TODO Auto-generated method stub
      }

}
这是运行结果
图片说明

  • 写回答

5条回答 默认 最新

  • 毕小宝 博客专家认证 2016-12-11 09:10
    关注
     还有一种可能就是你的Tomcat的编码设置没有统一,你搜一下Tomcat的server.xml的URIEncoding属性,配一下这个属性值为utf8。
    
    评论

报告相同问题?

悬赏问题

  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理