求救啊,该死的乱码
jsp页面form表单数据post到Action里面,Action里面使用sysout(request.getParameter("xxx"))在控制台上输出是乱码。
jdk:1.5
jsp:
contentType="text/html; charset=GBK" pageEncoding="GBK"java文件编码:GBK
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { request.setCharacterEncoding("GBK"); chain.doFilter(request, response); }<filter> <filter-name>encodingFilter</filter-name> <filter-class> org.springframework.web.filter.CharacterEncodingFilter </filter-class> <init-param> <param-name>encoding</param-name> <param-value>GBK</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter>
[解决办法]
字符转换一下
String str = new String(request.getAttribute("元素名").getBytes("ISO8859_1"),"GBK");
[解决办法]
在struts.xml中配置i18n
<constant name="struts.i18n.encoding" value="GB18030"></constant>