The error message "File Uploaded not found" is fixed in ueditor configuration in java. ueditor does not find

Source: Internet
Author: User

The error message "File Uploaded not found" is fixed in ueditor configuration in java. ueditor does not find

Ueditor is an online text editor with powerful functions. However, in the ssh framework, in struts2, the request and session objects need to be re-encapsulated by its interceptor, in this process, some content saved in the request object will be cleared, so the ueditor upload function will not be able to get the content to be uploaded, resulting in the "file not found" error!

Referring to the online materials and self-experiment, the final solution is to rewrite a converted class in struts2, and then configure struts2 to use the class we override. Because our project may have other upload and other functions, in order not to affect other functions, we need to add another filter. The role of this filter is: only for the ueditor upload function. For details about the location where ueditor needs to be modified and configured in java, Baidu does not provide relevant information. Here only describes how to solve the "file not found" error. The specific solution is as follows: Step 1: rewrite the struts2 converter. The content of the rewrite class is as follows:
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     {   }  }
The method here is an empty method, but the second step is required: Configure struts. xml is used to allow struts2 to use our converter. The configuration method is in struts. add the following configuration in xml
<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" />
The name in the bean label is customized, and the class value is the location where the rewritable converter is located. The value in the constant label must be consistent with the name in the bean. The third step does not need to be modified for others: create a filter to filter ueditor upload requests. The filter code is as follows:
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. optional; 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) ;}}/*** Image Upload and file upload in 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 {}}

 

Here, the decideURI method only filters the jsp pages of the two ueditors. If there are other pages with the same names as the Two JSPs in your project, it is best to change the full path of the two pages in ueditor. Step 4: configure this filter in the project web. xml, which should be placed before the struts2 interceptor, as shown below:
<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>

The filter-mapping label must be configured before the struts2 interceptor.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.