问题原因:
ueditor 上传图片需请求imageUp.jsp文件,struts2 自带的拦截器(/*)把所有请求的文件都做了处理,所以导致无法上传图片。
解决方法:
方法一:自定义拦截器,让它在请求imageUp.jsp文件时不做处理。
1 import java.io.IOException; 2 import javax.servlet.FilterChain; 3 import javax.servlet.ServletException; 4 import javax.servlet.ServletRequest; 5 import javax.servlet.ServletResponse; 6 import javax.servlet.http.HttpServletRequest; 7 import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter; 8 9 public class MyStrutsFilter extends StrutsPrepareAndExecuteFilter { 10 public void doFilter(ServletRequest req, ServletResponse res,FilterChain chain) throws IOException, ServletException { 11 HttpServletRequest request = (HttpServletRequest) req; 12 //不过滤的url 13 String url = request.getRequestURI(); 14 System.out.println(url); 15 if ("/yourWebName/ueditor/server/upload/jsp/imageUp.jsp".equals(url)) { 16 System.out.println("使用自定义的过滤器"); 17 chain.doFilter(req, res); 18 }else{ 19 System.out.println("使用默认的过滤器"); 20 super.doFilter(req, res, chain); 21 } 22 } 23 }
方法二:修改struts2 默认拦截器
1 <!--struts2过滤器 --> 2 <filter> 3 <filter-name>struts2</filter-name> 4 <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> 5 </filter> 6 <filter-mapping> 7 <filter-name>struts2</filter-name> 8 <url-pattern>*.do</url-pattern> 9 </filter-mapping>
这两种方法任选其一即可。