Solve some problems with jsp version ueditor1.2.5 (image uploading failed)

Source: Internet
Author: User

1. Questions about Image Upload failure

First import the jar package
Commons-fileupload-1.2.2.jar, ueditor. jar

Modify editor_config.js

Find and modify the URL to window. UEDITOR_HOME_URL | "/mypro/ueditor/". mypro is the name of my project.

Modify imagePath to URL + "upload /"
Suppose our image storage path is ueditor/upload/

Modify imageUp. jsp
Up. setSavePath ("") to up. setSavePath ("../imageUp ");
In this way, set the image storage path to ueditor/upload/imageUp.

If the struts2 interceptor is not configured in web. xml, the upload should be successful. If you need to combine the struts2 interceptor, you need to add additional configurations.

The principle is to create an interceptor, replace the default interceptor, and filter the paths that do not need to be intercepted.

First, create an interceptor class.

Copy codeThe Code is as follows: public class MyStrutsFilter extends StrutsPrepareAndExecuteFilter {
Public void doFilter (ServletRequest req, ServletResponse res,
FilterChain chain ){
HttpServletRequest request = (HttpServletRequest) req;
String url = request. getRequestURI ();
If (url. contains ("ueditor/jsp/") {<SPAN style = "WHITE-SPACE: pre"> </SPAN> // filter all files in the folder.
Try {
Chain. doFilter (req, res );
} Catch (IOException e ){
E. printStackTrace ();
} Catch (ServletException e ){
E. printStackTrace ();
}
} Else {
Try {
Super. doFilter (req, res, chain); // use the interceptor of the default parent class, that is, struts2
} Catch (IOException e ){
E. printStackTrace ();
} Catch (ServletException e ){
E. printStackTrace ();
}
}
}
}

Then define in web. xml

Copy codeThe Code is as follows: <? Xml version = "1.0" encoding = "UTF-8"?>
<Web-app version = "3.0"
Xmlns = "http://java.sun.com/xml/ns/javaee"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemaLocation = "http://java.sun.com/xml/ns/javaee
Http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd>
<Display-name> </display-name>
<Welcome-file-list>
<Welcome-file> index. jsp </welcome-file>
</Welcome-file-list>
<Session-config>
<Session-timeout> 30 </session-timeout>
</Session-config>
<Filter>
<Filter-name> struts2 </filter-name>
<Filter-class>
Cn. xyx. web. filter. MyStrutsFilter
<! -- The Custom interceptor is used here, And. jsp is not processed. Others use the default Interceptor-
Note that the default struts2 interceptor org. apache. struts2.dispatcher. ng. filter. StrutsPrepareAndExecuteFilter is replaced here -->
</Filter-class>
</Filter>
<Filter-mapping>
<Filter-name> struts2 </filter-name>
<Url-pattern>/* </url-pattern>
</Filter-mapping>
<Error-page>
<Error-code> 404 </error-code>
<Location>/404.jsp</location>
</Error-page>
</Web-app>

In this way, you can configure

Related Article

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.