For the xheditor environment, see http://blog.csdn.net/itmyhome1990/article/details/38422255. At this time, the image search function does not have an upload button.
If you want to see the upload button, set the following parameters in xheditor:
Html5upload: false// This attribute must be false
Upimgurl: "imgupload. Action"// Upload server interface
Onupload: insertupload// Server return information, in JSON format
I. Front-end code
<SCRIPT type = "text/JavaScript"> $ (function () {$ ('# content '). xheditor ({tools: 'full', // You can also customize tools. Full html5upload: false, // This attribute must be false; otherwise, the image cannot be uploaded. upimgurl: "imgupload. action ", onupload: uploadimg}); function uploadimg (data ){//... callback Function }}) </SCRIPT>
<body><div align="center"><textarea rows="20" cols="110" id="content"></textarea></div></body>
Ii. struts2 upload code
Public class imguploadaction extends actionsupport {private string err = ""; private string MSG; // return information private file filedata; // Upload File private string filedatafilename; // file name Public String imgupload () {// get response, request object actioncontext AC = actioncontext. getcontext (); httpservletresponse response = (httpservletresponse) AC. get (servletactioncontext. http_response); httpservletrequest request = (httpservlet Request) AC. get (servletactioncontext. http_request); response. setcontenttype ("text/html; charset = GBK"); printwriter out = NULL; try {out = response. getwriter () ;}catch (ioexception E1) {e1.printstacktrace () ;}string saverealfilepath = servletactioncontext. getservletcontext (). getrealpath ("/upload"); file filedir = new file (saverealfilepath); If (! Filedir. exists () {// create filedir if it does not exist. mkdirs ();} file SaveFile; SaveFile = new file (saverealfilepath + "/" + filedatafilename); try {fileutils. copyfile (filedata, SaveFile);} catch (ioexception e) {err = "error" + E. getmessage (); E. printstacktrace ();} string filename = request. getcontextpath () + "/upload/" + filedatafilename; MSG = "{\" Err \ ": \" "+ err +" \ ", \" MSG \": \ "" + filename + "\"} "; out. print (MSG); // return MSG information return NULL;} Public String geterr () {return err;} public void seterr (string ERR) {This. err = err;} Public String getmsg () {return MSG;} public void setmsg (string MSG) {This. MSG = MSG;} public file getfiledata () {return filedata;} public void setfiledata (File filedata) {This. filedata = filedata;} Public String getfiledatafilename () {return filedatafilename;} public void setfiledatafilename (string filedatafilename) {This. filedatafilename = filedatafilename ;}}
Iii. struts2 configuration file
<struts><package name="build" extends="struts-default"><action name="ImgUpload" method="imgUpload"class="com.itmyhome.ImgUploadAction"></action></package></struts>
Effect
Download project demo source code: to be displayed