<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 和風細雨 閱讀(808) 評論(0)  編輯  收藏 所屬分類: Struts


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


    網站導航:
     
    主站蜘蛛池模板: 亚洲性在线看高清h片| 免费无遮挡无码视频在线观看| 亚洲高清在线观看| 亚洲图片激情小说| 久久亚洲私人国产精品| 亚洲高清视频在线观看| 久久精品国产亚洲AV无码偷窥 | 久久免费香蕉视频| 日韩在线观看免费| 亚洲国产成人久久综合一| 国产V亚洲V天堂无码| 国产成人免费a在线视频app| 最近中文字幕mv手机免费高清| 97在线线免费观看视频在线观看| fc2成年免费共享视频18| 一级人做人爰a全过程免费视频| 国产精品一区二区三区免费| 中文在线免费观看| 午夜无码A级毛片免费视频| 亚洲AV成人片无码网站| 疯狂做受xxxx高潮视频免费| 亚洲国产日韩女人aaaaaa毛片在线| 亚洲精品无码专区2| 好爽…又高潮了毛片免费看| 久久九九全国免费| 国产亚洲高清在线精品不卡 | 亚洲精品制服丝袜四区| 久久99国产亚洲精品观看| 亚洲精品国产福利在线观看| 一本色道久久88—综合亚洲精品| 亚洲熟妇无码av另类vr影视 | 亚洲一区中文字幕久久| 33333在线亚洲| 青青草原精品国产亚洲av| 99热亚洲色精品国产88| 337p日本欧洲亚洲大胆人人 | 久久精品国产亚洲AV忘忧草18| 亚洲国产精品va在线播放| 亚洲欧洲日产v特级毛片| 亚洲日本VA午夜在线电影| 亚洲AV无码一区二区三区在线|