struts下的乱码问题的解决办法

类别:Java 点击:0 评论:0 推荐:
1、页面提示信息乱码
页面的提示信息来自ApplicationResources_zh.properties
解决方法:
(1)所有jsp页面均要用
<%@ page language="java" contentType="text/html; charset=GBK" %>
指出当前页面的charset
(2)用notepad等工具(而不是Eclipse Editor)编写中文资源文件,比如ApplicationResources_xx.properties。然后用工具native2ascii将资源文件中的中文字符转换为GBK,方法是在DOS下
native2ascii -encoding GBK ApplicationResources_xx.properties ApplicationResources_zh.properties

2、提交的中文字符在服务器端(JBOSS)乱码
解决办法:增加一个filter,里面将request中的中文转换为GBK
 public void doFilter(ServletRequest request, ServletResponse response,
   FilterChain chain) throws IOException, ServletException {
     request.setCharacterEncoding("GBK");
     chain.doFilter(request,response);
 }

本文地址:http://com.8s8s.com/it/it14244.htm