request.getParameter编码的问题

seawyt 发布于 2014/09/23 12:25
阅读 833
收藏 0

jsp:

<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>

<form action="/track" method="POST">

<input name="title" value="中国" type="text">

tomcat7.0.55:

 <Connector port="80" protocol="HTTP/1.1" URIEncoding="utf-8" useBodyEncodingForURI="true"

servlet3:

@WebServlet(name="hello",urlPatterns="/hello",asyncSupported=true) 

doPost{

System.out.println(request.getCharacterEncoding()); //不知道为什么此处为null?

request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("UTF-8");

System.out.println(request.getCharacterEncoding());//utf-8

String title = request.getParameter("title");//得到乱码!

new String(sSrc.getBytes("iso8859-1"), "UTF-8") //得到中文

}

请教下:过去在jsp、web.xml后后台统一设置utf-8编码后,不需要考虑转码的问题,此处不知道哪里出了问题?


加载中
返回顶部
顶部