jsp <input text> post提交到action 中文乱码
我在jsp的页面中有一个<input type="text" name="name" id="name"/> 然后post方式提交到action,在action中String name接收,但name却是乱码,如何解决?
环境:tomcat6+jdk1.6+myeclipse6.5+struts2
我已试过如下方法:
1、在jsp页面中加<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
2、把java改成utf-8
[解决办法]
String str= new String((req.getParameter("XXX")).getBytes("ISO-8859-1"),"UTF-8")这样试下 UTF-8可以换成你要的
[解决办法]
request.setCharacterEncoding("utf-8");
[解决办法]
改成gb2312
[解决办法]
可以试一下GB2312 格式
[解决办法]
struts2中的拦截器,处理一下,网上有源码!
[解决办法]
public class EncodingFilter implements Filter
{
public void destroy()
{
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
request.setCharacterEncoding("UTF-8");
chain.doFilter(request,response);
}
public void init(FilterConfig arg0) throws ServletException
{
}
}
<filter>
<filter-name>encoding</filter-name>
<filter-class>
com.shfft.filter.EncodingFilter
</filter-class>
</filter>