servlet中doGet和doPost字符乱码问题

 protected void doGet(HttpServletRequest req, HttpServletResponse resp)   throws ServletException, IOException {

 

}

doGet中调用:    resp.setContentType("text/html;charset=gbk");

 

protected void doPost(HttpServletRequest req, HttpServletResponse resp)   throws ServletException, IOException {

 }

doPost中,调用:req.setCharacterEncoding("GBK");

同时在Tomcat/cnfg/server.xml中标签中加入URIEncoding="GBK"

例:

                   connectionTimeout="20000"
               redirectPort="8443" URIEncoding="GBK" />

 

注意:在处理doGet和doPost乱码问题时所调用的语句一定要写在存取第一个参数之前!

你可能感兴趣的:(Java)