<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中配置這個(gè)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ì)雨 閱讀(808) 評(píng)論(0)  編輯  收藏 所屬分類: Struts


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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲国产午夜精品理论片在线播放| 亚洲av日韩av高潮潮喷无码 | 日本免费人成黄页在线观看视频| 亚洲高清在线mv| 日韩免费的视频在线观看香蕉| 国产亚洲色视频在线| 久久精品无码免费不卡| 亚洲区日韩区无码区| 久久国产精品免费一区二区三区| 亚洲免费在线观看| GOGOGO高清免费看韩国| 中文字幕一精品亚洲无线一区| 国产精品高清免费网站 | 久久午夜羞羞影院免费观看| 亚洲国产精品第一区二区| 99蜜桃在线观看免费视频网站| 亚洲美女视频一区二区三区| 精品久久久久久久久免费影院| 亚洲宅男精品一区在线观看| 日本一道一区二区免费看| 四虎成人精品国产永久免费无码| 中文字幕亚洲无线码| 久久久久免费精品国产| 亚洲毛片基地日韩毛片基地| 成年人免费网站在线观看| 精品久久久久久亚洲综合网| 国产亚洲自拍一区| 日韩在线不卡免费视频一区| 亚洲a视频在线观看| 国产hs免费高清在线观看| 国产精品成人免费观看| 亚洲精品在线免费观看| 日韩在线看片免费人成视频播放| 成人免费夜片在线观看| 久久久久亚洲精品无码蜜桃| 好吊妞在线新免费视频| 中国内地毛片免费高清| 亚洲人精品亚洲人成在线| 国产精品亚洲综合专区片高清久久久 | 中文字幕亚洲激情| 波多野结衣免费在线观看|