Use the xheditor and strut2 configurations and upload images!

Source: Internet
Author: User

The JS file is as follows:

$ (Pageinit); function pageinit () {// This is the plug-in used to compile code online. After this plug-in is used, the program questions will be built into the full style and tools will be used: 'full' can call var plugins = {code: {C: 'btncode', T: 'code', H: 1, E: function () {VaR _ this = this; vaR htmlcode = '<div> <select id = "xhecodetype"> <option value = "html"> html/XML </option> <option value = "JS"> JavaScript </option> <option value = "CSS"> CSS </option> <option value = "php"> php </option> <option value = "Java"> JAVA </ option> <option value = "py"> python </option> <option value = "PL"> perl </option> <option value = "rb"> ruby </Option> <option value = "CS"> C # </option> <option value = "C"> C ++/C </option> <option value = "VB"> vb/asp </option> <option value = ""> others </option> </SELECT> </div> <textarea id = "xhecodevalue" Wrap =" soft "spellcheck =" false "style =" width: 300px; Height: 100px; "/> </div> <Div style =" text-align: right; "> <input type =" button "id =" xhesave "value =" OK "/> </div> '; var jcode = $ (htmlcode ), jtype = $ ('# xhecodetype', jcode), jvalue = $ ('# xhecodevalue', jcode), jsave = $ (' # xhesave ', jcode); jsave. click (function () {_ this. loadbookmark (); _ this. pastehtml ('<PRE class = "prettyprint Lang-' + jtype. val () + '">' + _ this. domencode (jvalue. val () + '</PRE>'); _ this. hidepanel (); Return false ;}); _ this. showdialog (jcode) ;}}; // comment out/* all styles * // $ ('. myeditor '). xheditor ({tools: 'full', skin: 'o2007sil', plugins: plugins, loadcss: '<style> pre {margin-left: 1em; border-left: 5px solid #68b839; padding: 0 1em ;}</style> ', upimgurl: 'xheditor', upimgext: 'jpg, JPEG, GIF, PNG, BMP', forceptag: false}); // $ ('. myeditor '). xheditor ({skin: 'o2007sil', html5upload: false, upmultiple: '1', upimgurl: 'xheditor', upimgext: 'jpg, JPEG, GIF, BMP, PNG ', uplinkurl: 'upload. do ', uplinkext: 'zip, rar, txt, docx, Doc, xls, XLSX, PDF'});/* simple style * // $ ('. myeditor '). xheditor ({tools: 'mini ', skin: 'o2007silver'}); $ ('. myeditor '). xheditor ({tools: 'full', skin: 'o2007sil', plugins: plugins, loadcss: '<style> pre {margin-left: 1em; border-left: 5px solid #68b839; padding: 0 1em ;}</style> ', upmultiple: false, upimgurl: "/onlinetest/jrpc", upimgext: "JPG, JPEG, GIF, BMP, PNG ", onupload: insertupload}); function insertupload (MSG) {VaR _ MSG = MSG. tostring (); VaR _ picture_name = _ MSG. substring (_ MSG. lastindexof ("/") + 1); VaR _ picture_path = substring (_ MSG ); vaR _ STR = "<input type = 'checkbox' name = '_ Pictures' value ='" + _ picture_path + "'checked = 'checked' onclick = 'Return false '/> <label> "+ _ picture_name +" </label> <br/> "; $ ("# myeditor "). append (_ MSG); // $ ("# uploadlist "). append (_ Str);} // The string content returned by the processing server to the callback function. The format is JSON. function substring (s) {return S. substring (S. substring (0, S. lastindexof ("/")). lastindexof ("/"), S. length);}/* Custom style * // modify the tools parameter to complete the button table: // |: separator/: Forced line feed cut: Cut copy: Copy paste: paste pastetext: Text paste blocktag: paragraph tag fontface: fontsize: font size bold: bold italic: italic // underline: underline strikethrough: underlined fontcolor: fontcolor backcolor: font background color selectall: All selected removeformat: delete text format align: Align: Alignment list: List outdent: reduce indent // indent: Add indent link: hyperlink unlink: delete link anchor: Anchor: anchimg: picture FLASH: Flash Animation HR: insert horizontal line // table: Table Source: Switch source code mode preview: preview current Code print: Print fullscreen: Switch full screen mode // $ ('. myeditor '). xheditor ({tools: 'Cut, copy, paste, pastetext, underline, removeformat, source, Link, unlink, fontsize, preview, fullscreen ', skin: 'o2007silver '});}

The Servlet used here, you need to add servlet in strust2. You need to add filter, otherwise struts2

The filter class is as follows:

import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import javax.servlet.Filter;import javax.servlet.FilterChain;import javax.servlet.FilterConfig;import javax.servlet.RequestDispatcher;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServletRequest;public class UploadFilter implements Filter {public void destroy() {}public void doFilter(ServletRequest req, ServletResponse resp,FilterChain chain) throws IOException, ServletException {HttpServletRequest request = (HttpServletRequest) req;String target = request.getRequestURI();target = target.lastIndexOf("?") > 0 ? target.substring(target.lastIndexOf("/") + 1, target.lastIndexOf("?")- target.lastIndexOf("/")) : target.substring(target.lastIndexOf("/") + 1);// System.out.println(target);if (this.includes.contains(target)) {RequestDispatcher rdsp = request.getRequestDispatcher(target);// System.out.println("go..............." + rdsp);rdsp.forward(req, resp);} elsechain.doFilter(req, resp);}private ArrayList<String> includes = new ArrayList<String>();public void init(FilterConfig config) throws ServletException {this.includes.addAll(Arrays.asList(config.getInitParameter("includeServlets").split(",")));}}

In the Web. xml file, add the following before the filter of sturts2:

<Filter> <filter-Name> jsonrpcservlet </filter-Name> <filter-class> hhxy. jsjcxsy. onlinetest. web. struts2.filter. uploadfilter </filter-class> <init-param> <param-Name> basedir </param-Name> <param-value>/article_img </param-value> </init -param> <init-param> <param-Name> fileext </param-Name> <param-value> JPG, JPEG, GIF, BMP, PNG </param-value> </init-param> <param-Name> maxsize </param-Name> <param-value> 1024000 </PA Ram-value> </init-param> <param-Name> dirtype </param-Name> <param-value> 1 </param-value> </init-param> <param-Name> includeservlets </param-Name> <param-value> jrpc </param-value> <! -- Note: jrpc configures the servlet jsonrpcservlet filter requests configured below --> </init-param> </filter> <filter-mapping> <filter-Name> jsonrpcservlet </filter-Name> <URL-pattern>/* </url-pattern> </filter-mapping> <servlet-Name> jsonrpcservlet </servlet-Name> <servlet-class> hhxy. jsjcxsy. onlinetest. servlet. uploadfileservlet </servlet-class> <load-on-startup> 2 </load-on-startup> </servlet> <servlet-mapping> <servlet-Name> jsonrpcservlet </ servlet-Name> <URL-pattern>/jrpc </url-pattern> </servlet-mapping>

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.