1)采用國際化。這樣能解決頁(yè)面的中文亂碼問(wèn)題。
a)把頁(yè)面中所出現的中文寫(xiě)到屬性文件中,例如: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)頁(yè)面統一采用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集成的類(lèi)
- <!-- 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類(lèi)把請求的統一轉換成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文件(可能這個(gè)就能取代上面的,有待測試)中加入
- webwork.custom.i18n.resources=messages
- webwork.locale=zh_CN
- webwork.i18n.encoding=GBK
f)在頁(yè)面中還需添加JSTL標簽,當然在classpath下要加入相關(guān)的類(lèi)包
- <%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %><span style="font-family: Arial, Helvetica, sans-serif;"> </span>
g)現在在頁(yè)面中就可以采用jstl的EL來(lái)引入了
- <fmt:message key="shipment.shipment"/>
2)把tomcate下面的conf文件夾下的server.xml文件中加入 URIEncoding="GBK",有了上面的可能這一個(gè)也是多余的,如:
- <Connector
- port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
- enableLookups="false" redirectPort="8443" acceptCount="100"
- debug="0" connectionTimeout="20000"
- disableUploadTimeout="true" URIEncoding="GBK" />
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請
點(diǎn)擊舉報。