fmt:message 中文乱码问题

1)采用国际化。这样能解决页面的中文乱码问题。

a)把页面中所出现的中文写到属性文件中,例如:messages_zh.properties,

shipment.system = 出货小系统
shipment.jsnum = 条码
shipment.stylenum = 款式
b)native2ascii把文字转换成ascii码,
D:\project\shipment\web\WEB-INF\classes>native2ascii messages_zh.properties mess
ages_zh_CN.properties

c)页面统一采用utf-8编码
<%@ page pageEncoding="utf-8" contentType="text/html;charset=utf-8" %>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
d)在web.xml文件中引入JSTL与WEBWORK集成的类
<!-- Define the basename for a resource bundle for I18N -->
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>messages</param-value>
</context-param>
<!-- 采用filter编码转换-->
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>org.appfuse.web.SetCharacterEncodingFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
 
e)filter类把请求的统一转换成utf-8,(在2.1.7版本以后自己处理好了)如下:
package org.appfuse.web;

/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2005-8-11
* Time: 13:17:00
* To change this template use File | Settings | File Templates.
*/
import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class SetCharacterEncodingFilter implements Filter{

public void init(FilterConfig arg0) throws ServletException {

}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
/*
* Servlet编码
*/
request.setCharacterEncoding("utf-8"); 
chain.doFilter(request,response);
}

public void destroy() {

}

}
  
e)在web-inf\classes中的webwork.properties文件(可能这个就能取代上面的,有待测试)中加入
webwork.custom.i18n.resources=messages
webwork.locale=zh_CN
webwork.i18n.encoding=GBK
 
f)在页面中还需添加JSTL标签,当然在classpath下要加入相关的类包
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>   
g)现在在页面中就可以采用jstl的EL来引入了
<fmt:message key="shipment.shipment"/>
2)把tomcate下面的conf文件夹下的server.xml文件中加入 URIEncoding="GBK",有了上面的可能这一个也是多余的,如:
<Connector 
port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000" 
disableUploadTimeout="true" URIEncoding="GBK" />

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不讲理的胖子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值