UEditor 上傳圖片 提示未找到上傳資料
阿新 • • 發佈:2019-01-09
寫一個過濾器
import java.io.IOException; import javax.servlet.FilterChain; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter; public class MyEditorStrutsFilter extends StrutsPrepareAndExecuteFilter{ @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; String url = request.getRequestURI(); if (url.contains(request.getContextPath()+"/ueditor/jsp/")) { chain.doFilter(req, res); }else{ super.doFilter(req, res, chain); } } }
將web.xml 裡的
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
替換為
<filter>
<filter-name>myeditor</filter-name>
<filter-class>gov.zb.data.filter.MyEditorStrutsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>myeditor</filter-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.action</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>