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

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

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

    和風細雨

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

    如何配置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調用示例:
    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中參數name
            String name = (String) PropertyUtils.getSimpleProperty(form, "name");
            
            request.setAttribute(
    "msg""歡迎你!"+name);

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

    }


    以上。

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


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


    網站導航:
     
    主站蜘蛛池模板: 亚洲乱码国产一区三区| 亚洲一级大黄大色毛片| 亚洲中文字幕无码永久在线| 亚洲人成影院在线| 亚洲国产欧洲综合997久久| 国内精品免费久久影院| 成人免费无码大片A毛片抽搐| 在线观看亚洲成人| 成人精品视频99在线观看免费| 毛片免费在线视频| 久久精品熟女亚洲av麻豆| 91久久青青草原线免费| 国产亚洲人成A在线V网站| 亚洲一区二区三区成人网站| 国产白丝无码免费视频| 亚洲午夜日韩高清一区| 亚洲精品无码成人| 亚洲黄色免费网址| 亚洲人成网亚洲欧洲无码久久| 视频免费1区二区三区| 成人啪精品视频免费网站| 欧美色欧美亚洲另类二区| 美女视频黄是免费的网址| 亚洲AV中文无码乱人伦下载| 噜噜噜亚洲色成人网站| 最近2019中文字幕免费看最新 | 久久99九九国产免费看小说| 亚洲影视自拍揄拍愉拍| 69影院毛片免费观看视频在线| 亚洲冬月枫中文字幕在线看| 免费无码VA一区二区三区| 亚洲成A人片在线观看WWW| 国产精品免费一区二区三区| 亚洲日韩在线第一页| 99爱免费观看视频在线| 亚洲av永久无码天堂网| 亚洲中文字幕无码久久精品1| 国产黄色免费网站| 亚洲综合成人婷婷五月网址| 久久不见久久见中文字幕免费| 亚洲人成网站18禁止久久影院|