Struts2 FCKeditor 文件上传解决

在struts2的Filter之前配一个过滤器,拦截"/fckeditor/editor/filemanager/connectors/*"再做forward转发, 目的是绕过Struts2的过滤器

public class FckeditorUploadFilter implements Filter {

private String DispatcherUrl;  
     public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain)  
               throws IOException,ServletException{  
         HttpServletRequest httprequest = (HttpServletRequest) request;  
         if(httprequest.getParameter("Command")!=null&&  
                 httprequest.getParameter("Command").equals("FileUpload")){  
             httprequest.getRequestDispatcher(DispatcherUrl).forward(request, response);  
         }else{  
             chain.doFilter(request, response);  
         }  
     }  
     /** 
      * Initialization of the servlet. <br> 
      * 
      * @throws ServletException if an error occure 
      */ 
     public void init(FilterConfig config){  
         // Put your code here  
         DispatcherUrl=config.getInitParameter("DispatcherUrl");  
     }  
     public void destroy(){  
           
     }  

}
web.xml里面的过滤器

<filter>  
   <filter-name>FckeditorUploadFilter</filter-name>  
    <filter-class>  
        com.util.FckeditorUploadFilter  
    </filter-class>  
    <init-param>  
        <param-name>DispatcherUrl</param-name>  
        <param-value>/fckeditor/editor/filemanager/connectors/</param-value>  
    </init-param>  
</filter>  
<filter-mapping>  
    <filter-name>FckeditorUploadFilter</filter-name>  
    <url-pattern>  
        /fckeditor/editor/filemanager/connectors/*  
    </url-pattern>  
</filter-mapping>  

你可能感兴趣的:(Web,xml,servlet,fckeditor)