<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    love fish大鵬一曰同風起,扶搖直上九萬里

    常用鏈接

    統計

    積分與排名

    friends

    link

    最新評論

    Struts+Hibernate中解決漢字編碼問題(轉)

    1. 首先所有的文字編碼均采用UTF-8格式,至于為什么要采用UTF-8.  
    <%@ page language="java" contentType="text/html; charset=utf-8" %>

    2. struts框架提供了資源信息文件,它包含了jsp頁面內容的一些文字說明,以及另一些供代碼中使用的信息輸出等(說白了,就是些文字描述定義,可以當成變量看待)。
    ApplicationResources.properties(默認的是英文ApplicationResources.properties一份,命名為:ApplicationResources_zh_CN.properties 簡體中文
    ApplicationResources_zh_TW.properties 繁體中文
     
    然后,執行JDK自帶的命令如下:
    native2ascii -encoding gb2312 ApplicationResources_demo.properties ApplicationResources_zh_CN.properties
    3. struts中,對于中文參數的傳遞的文字編碼處理,一般加個過濾器類就可以了的。
    java源代碼如下:

    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;
    import javax.servlet.UnavailableException;


    public class SetCharacterEncodingFilter implements Filter
    {
    ?protected String encoding = null;
    ?protected FilterConfig filterConfig = null;
    ?protected boolean ignore = true;
    ?
    ?public void destroy()
    ?{
    ??this.encoding = null;
    ??this.filterConfig = null;
    ?}

    ?public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain)
    ???throws IOException, ServletException
    ?{
    ??if (ignore || (request.getCharacterEncoding() == null))
    ??{
    ???String encoding = selectEncoding(request);
    ???if (encoding != null)
    ????request.setCharacterEncoding(encoding);
    ??}
    ??chain.doFilter(request, response);
    ?}

    ?public void init(FilterConfig filterConfig) throws ServletException
    ?{
    ??this.filterConfig = filterConfig;
    ??this.encoding = filterConfig.getInitParameter("encoding");
    ??String value = filterConfig.getInitParameter("ignore");
    ??if (value == null)
    ???this.ignore = true;
    ??else if (value.equalsIgnoreCase("true"))
    ???this.ignore = true;
    ??else if (value.equalsIgnoreCase("yes"))
    ???this.ignore = true;
    ??else
    ???this.ignore = false;
    ?}

    ?protected String selectEncoding(ServletRequest request)
    ?{
    ??return (this.encoding);
    ?}
    }
    4.? 配置web.xml文件

    ? 在<web-app>下加下面的代碼

    <filter>
    ?<filter-name>Set Character Encoding</filter-name>
    ?<filter-class>com.zxjsoft.util.SetCharacterEncodingFilter</filter-class>
    ?<init-param>
    ??<param-name>encoding</param-name>
    ??<param-value>utf-8</param-value>
    ?</init-param>
    ?<init-param>
    ??<param-name>ignore</param-name>
    ??<param-value>true</param-value>
    ?</init-param>
    </filter>

    <filter-mapping>
    ?<filter-name>Set Character Encoding</filter-name>
    ?<servlet-name>action</servlet-name>
    </filter-mapping>

    5.對于hibernate如說 還得配置hibernate.cfg.xml文件
    ?在文件里加入
    ?<property name="hibernate.connection.useUnicode">true</property>
    ?<property name="hibernate.connection.characterEncoding">UTF-8(或者gb2312)</property>

    posted on 2007-03-23 09:42 liaojiyong 閱讀(612) 評論(0)  編輯  收藏 所屬分類: Struts

    主站蜘蛛池模板: 中文字幕不卡高清免费| 亚洲欧美日韩中文字幕一区二区三区| 一级毛片完整版免费播放一区| 拍拍拍又黄又爽无挡视频免费| 亚洲成人一级电影| 国产在线观看麻豆91精品免费| 337p日本欧洲亚洲大胆色噜噜| 污视频在线观看免费| 亚洲AV无码一区二区三区系列| 日本在线看片免费| 久久精品亚洲精品国产色婷| 亚洲精品免费在线观看| 亚洲美女一区二区三区| 日韩精品福利片午夜免费观着| 日本亚洲色大成网站www久久 | 久久免费看黄a级毛片| 久久久久久亚洲精品成人| 无码国产精品一区二区免费虚拟VR| 亚洲人成在线中文字幕| 成人免费无码大片a毛片软件| 国产精品亚洲av色欲三区| 亚洲天堂中文字幕在线| 久久国产精品萌白酱免费| 亚洲女人影院想要爱| 免费黄色app网站| 一级**爱片免费视频| 亚洲午夜视频在线观看| 最近最好的中文字幕2019免费| 亚洲av无码专区首页| 国产亚洲美女精品久久久2020| 久久免费福利视频| 亚洲另类自拍丝袜第五页| 亚洲精品久久久www| 99在线热视频只有精品免费| 亚洲日韩久久综合中文字幕| 亚洲天堂免费在线视频| 日本片免费观看一区二区| 猫咪免费人成网站在线观看入口| 久久国产精品亚洲一区二区| 小小影视日本动漫观看免费| 久久嫩草影院免费看夜色|