为什么这段代码不能解决post和get方式提交时乱码问题?(看过方立勋老师讲的JAVA web视频《request response(第六天)》之后写的) 我的IE浏览器的编码表是UTF-8还有一个简单的JSP表单提交页面! package cn.itcast.ResPonse; 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; public class Serv extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name=request.getParameter("name"); name=new String (name.getBytes("iso8859-1"),"UTF-8"); System.out.println(name); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); String name=request.getParameter("name"); System.out.println(name); } } |