标签:des style blog http java color
ueditor是一个功能十分强大的在线文本编辑器,但是在ssh框架中,确切的说实在struts2中由于其拦截器需要对request,session对象进行重新封装,这个过程中会把request对象中保存的一些内容清空,所以会导致ueditor的上传功能获取不到需要上传的内容导致“未找到上传文件”的错误!
import java.io.IOException; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest; public class RequestParseWrapper extends JakartaMultiPartRequest { public void parse(HttpServletRequest servletRequest, String saveDir)throws IOException { } }
<bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest" name="myRequestParser" class="com.lsra.tools.uedior.RequestParseWrapper" scope="default" optional="true" /> <constant name="struts.multipart.handler" value="myRequestParser" />
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; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.dispatcher.StrutsRequestWrapper; public class UeditorFilter implements Filter { @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; String url = request.getRequestURI(); if (decideURI(url)) { chain.doFilter(new StrutsRequestWrapper((HttpServletRequest) req), res); }else{ chain.doFilter(req, res); } } /** * ueditor编辑器中的图片上传和文件上传 * @param url * @return */ private boolean decideURI(String url){ if(url.endsWith("imageUp.jsp")){ return true; }else if(url.endsWith("fileUp.jsp")){ return true; } return false; } @Override public void destroy() { } @Override public void init(FilterConfig filterConfig) throws ServletException { } }
<filter> <filter-name>ueditorFilter</filter-name> <filter-class> com.lsra.tools.uedior.UeditorFilter </filter-class> </filter> <filter-mapping> <filter-name>ueditorFilter</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping>
filter-mapping标签一定要配置到struts2拦截器的前面
java配置ueditor中解决“未找到上传文件”错误提示,布布扣,bubuko.com
标签:des style blog http java color
原文地址:http://www.cnblogs.com/ucfjepl/p/3851694.html