在struts2的项目中 使用FCK,上传图片报错。
找到原因:
struts2将请求全部拦截,修改web.xml。
方法一:因为struts2的请求,是/* 刚会全路径过滤。所以修改struts2的请求:
由<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
改为:
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/struts/*</url-pattern>
</filter-mapping>
- <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
- <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
- <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.js</url-pattern>
</filter-mapping>
方法二:写个struts2请求过滤的类来实现请求分向的Filter类
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
if(request.getRequestURI().indexOf("/fckeditor/editor/filemanager/connectors")>0)
{
chain.doFilter(req, res);
} else {
super.doFilter(req, res, chain);
}
}
把这个Filter类的<filter-class>覆盖原本的struts2的<filter-class>就可以实现。(待测)