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

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

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

    和風(fēng)細(xì)雨

    世上本無難事,心以為難,斯乃真難。茍不存一難之見于心,則運(yùn)用之術(shù)自出。

    如何配置filter解決Struts的中文問題

    1.制作一filter類如下:
    package com.sitinspring.filter;

    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 {
        
    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 {

            
    // Conditionally select and set the character encoding to be used
            if (ignore || (request.getCharacterEncoding() == null)) {
                String encoding 
    = selectEncoding(request);
                
    if (encoding != null)
                    request.setCharacterEncoding(encoding);
            }


            
    // Pass control on to the next filter
            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);
        }


    }


    2.在Web.xml中配置這個filter。
        <!-- filter -->
        
    <filter>
            
    <filter-name>Set Character Encoding</filter-name>
            
    <filter-class>com.sitinspring.filter.SetCharacterEncodingFilter</filter-class>
            
    <init-param>
                
    <param-name>encoding</param-name>
                
    <param-value>UTF-8</param-value>
            
    </init-param>
        
    </filter>
        
    <filter-mapping>
            
    <filter-name>Set Character Encoding</filter-name>
            
    <url-pattern>/*</url-pattern>
        
    </filter-mapping>

    3.Action調(diào)用示例:
    package com.sitinspring.action;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.apache.commons.beanutils.PropertyUtils;
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;

    /**
     * Action定義處
     * 
    @author sitinspring
     *
     * @date 2008-3-20
     
    */

    public final class HelloAction extends Action {
        
    public ActionForward execute(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response)
                
    throws Exception {
            request.setCharacterEncoding(
    "UTF-8");

            
    // 取Form中參數(shù)name
            String name = (String) PropertyUtils.getSimpleProperty(form, "name");
            
            request.setAttribute(
    "msg""歡迎你!"+name);

            
    return (mapping.findForward("SayHello"));
        }

    }


    以上。

    posted on 2008-03-20 12:46 和風(fēng)細(xì)雨 閱讀(799) 評論(0)  編輯  收藏 所屬分類: Struts


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 日本高清免费aaaaa大片视频| 又粗又黄又猛又爽大片免费| 亚洲精品~无码抽插| xxxx日本在线播放免费不卡| 久久久久亚洲精品天堂久久久久久 | 国产福利在线免费| 亚洲人成影院在线高清| 又粗又大又黑又长的免费视频| 97se亚洲国产综合自在线| 国内外成人免费视频| 区久久AAA片69亚洲| 亚洲一区二区三区在线网站 | 免费无码黄网站在线观看| 在线观看亚洲AV日韩A∨| 国内大片在线免费看| 色噜噜噜噜亚洲第一| 日韩亚洲变态另类中文| 特级无码毛片免费视频尤物| 亚洲国色天香视频| 精品久久久久久久免费人妻| 四虎影视永久在线精品免费| 亚洲午夜久久久影院| 免费观看激色视频网站(性色)| 亚洲一级片在线播放| 人人狠狠综合久久亚洲高清| 免费久久人人爽人人爽av| 亚洲人成网站在线观看播放动漫 | 亚洲老熟女五十路老熟女bbw| 亚洲国产V高清在线观看| 久久这里只精品99re免费| 亚洲AV无码乱码在线观看性色扶| j8又粗又长又硬又爽免费视频| 亚洲精品视频在线| 黄网址在线永久免费观看 | 曰批全过程免费视频网址| 亚洲欧美日韩综合久久久久| 亚洲色婷婷六月亚洲婷婷6月| 在线看免费观看AV深夜影院| 黄色免费网址在线观看| 国产成人免费永久播放视频平台 | 最近免费最新高清中文字幕韩国|