Jsp solves the problem of kindeditor online editor struts Image Upload, kindeditorstruts

Source: Internet
Author: User

Jsp solves the problem of kindeditor online editor struts Image Upload, kindeditorstruts

1. Download

Download ckeditor from the official website, decompress the package, and remove unnecessary parts. You only need to keep the plugin, lang, and theme folders. You can delete things that are not available in these three folders, for example, to store all language files under the lang file, just keep en. the json_upload.jsp file and kindeditor In the jsp folder can be retained. to import the jar files under jsp.

  

Online Editor: http://kindeditor.net/
 

 

2. Modify json_upload.jsp

Modify the Save path of the json_upload.jsp file.

// Path of the file storage directory
String savePath = pageContext. getServletContext (). getRealPath ("/upload ");

// File Save directory URL, which is an absolute path
String saveUrl = request. getContextPath () + "/upload ";

3. Optional

Obj. put ("url", request. getContextPath () + "/img/" + newFileName); // modify the image returned to the editor

4. Modify the parameters in plugins/images/image. js.

UploadJson = K. undef (self. uploadJson, self. basePath + 'jsp/upload_json.jsp ')

5. modify it in plugins/filemanager. js.

FileManagerJson = K. undef (self. fileManagerJson, self. basePath + 'jsp/file_manager_json.jsp '),

6. jsp

<Link rel = "stylesheet" href = "<% = application. getContextPath () %>/themes/default/default.css"/>
<Script charset = "UTF-8" src = "<% = application. getContextPath () %>/js/kindeditor. js"> </script>
<Script charset = "UTF-8" src = "<% = application. getContextPath () %>/lang/zh_CN.js"> </script>

<Script charset = "UTF-8" src = "<% = application. getContextPath () %>/lang/zh_CN.js"> </script>
<Script>
Var editor;
KindEditor. ready (function (K ){
Editor = K. create ('textarea [id = "content"] ', {
FilterMode: false,
ResizeType: 1,
AllowPreviewEmoticons: true,
AllowImageUpload: true,
Items :[
'Fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold ', 'italic', 'underline ',
'Removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist ',
'Insertunorderedlist', '|', 'emoticons', 'image', 'link']

});
K ('input [name = submit] '). click (function (e ){
Editor. value = editor. text ();
});
});
</Script>

<Textarea tabindex = "4" name = "brand. content" id = "content"> -------------------------- struts ----------------------------------------------------

1. struts directly <url-pattern>/* </url-pattern> blocks the url of the online editor. Therefore, you need to configure the following, this is only one of the solutions to that problem.

2. Custom filter

Public class KindeditorUrlFilter extends StrutsPrepareAndExecuteFilter {

@ Override
Public void doFilter (ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {

HttpServletRequest request = (HttpServletRequest) req;
// Unfiltered url
String url = request. getServletPath ();

If ("/js/jsp/file_manager_json.jsp". equals (url )){

Chain. doFilter (req, res );
} Else if ("/js/jsp/upload_json.jsp". equals (url )){
Chain. doFilter (req, res );
} Else {
// System. out. println ("use default filter ");
Super. doFilter (req, res, chain );
}
}
}

3. Configure filter in web. xml

<Filter>
<Filter-name> struts2 </filter-name>
<Filter-class> com. dan. action. KindeditorUrlFilter </filter-class>
</Filter>
<Filter-mapping>
<Filter-name> struts2 </filter-name>
<Url-pattern>/* </url-pattern>
</Filter-mapping>

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.