在servlet中出现中文乱码解决方法

request.setCharacterEncoding(“utf-8”);
response.setCharacterEncoding(“utf-8”);
response.setHeader(“Content-Type”, “text/html; charset=UTF-8”);

已标记关键词 清除标记
运行时显示乱码,试了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("<br/>"); out.write("请求的url地址:"+request.getRequestURL()); out.write("<br/>"); out.write("请求的资源:"+request.getRequestURI()); out.write("<br/>"); out.write("请求的URL地址附带的参数:"+request.getQueryString()); out.write("<br/>"); out.write("来访者的IP地址:"+request.getRemoteAddr()); out.write("<br/>"); out.write("来访者的主机名:"+request.getRemoteHost()); out.write("<br/>"); out.write("使用的端口号:"+request.getRemotePort()); out.write("<br/>"); out.write("remoteUser"+request.getRemoteUser()); out.write("<br/>"); out.write("请求使用的方法:"+request.getMethod()); out.write("<br/>"); out.write("pathInfo:"+request.getPathInfo()); out.write("<br/>"); out.write("localAddr:"+request.getLocalAddr()); out.write("<br/>"); out.write("localName:"+request.getLocalName()); out.write("<br/>"); out.close(); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } } 这是运行结果 ![图片说明](https://img-ask.csdn.net/upload/201612/11/1481447075_906150.png)
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页