Kindeditor Í ¼ Æ É Ï '«struts2 Ê µï Ö
Please» adjust your kindeditor when using vertical ° struts2 2 when using vertical bars '{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%, ~~~~%%%%%%%%kindeditor *****%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Please refer to the following link for more information: kindeditor íæ É Ï '«zookeeper jar° ü Ú úkindeditor \ jsp \ lib Ï Â Ó Ð
~~~~~~~Â á~~~ö² ~~~~äúâ, ~~è '«)
JSP
ÕâÀïÊäÈëÄÚÈÝ...
<script type="text/javascript"> $(function(){KindEditor.ready(function(K) { var editor1 = K.create('#editor_id', { //×Ô¶¨Ò幤¾ßÀ¸items:['code', '|', 'justifyleft', 'justifycenter', 'justifyright','justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent','clearhtml', 'quickformat', 'selectall', '|', 'fullscreen','formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold','italic', 'underline', 'strikethrough', 'lineheight', 'removeformat','|', 'image', 'multiimage','insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak','anchor', 'link', 'unlink'],uploadJson : 'ImgUpload.action', //ͼƬÉÏ´«ActionallowImageRemote : false //È¡ÏûÍøÂçͼƬÉÏ´«}); }); })</script>
Struts
Action
import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.PrintWriter;import java.text.SimpleDateFormat;import java.util.Arrays;import java.util.Date;import java.util.HashMap;import java.util.Random;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.commons.fileupload.FileItemFactory;import org.apache.commons.fileupload.disk.DiskFileItemFactory;import org.apache.commons.fileupload.servlet.ServletFileUpload;import org.apache.struts2.ServletActionContext;import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper;import org.json.simple.JSONObject;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;public class ImgUploadAction extends ActionSupport {private static final long serialVersionUID = 1L;public String imgUpload() {//»ñÈ¡response¡¢request¶ÔÏóActionContext ac = ActionContext.getContext();HttpServletResponse response = (HttpServletResponse) ac.get(ServletActionContext.HTTP_RESPONSE);HttpServletRequest request = (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);PrintWriter out = null; //Êä³öÁ÷try {out = response.getWriter();} catch (IOException e1) {e1.printStackTrace();}String savePath = ServletActionContext.getServletContext().getRealPath("/") + "attached/";// Îļþ±£´æÄ¿Â¼URLString saveUrl = request.getContextPath() + "/attached/";// ¶¨ÒåÔÊÐíÉÏ´«µÄÎļþÀÕ¹ÃûHashMap
extMap = new HashMap
();extMap.put("image", "gif,jpg,jpeg,png,bmp");extMap.put("flash", "swf,flv");extMap.put("media", "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb");extMap.put("file", "doc,docx,xls,xlsx,ppt,htm,html,txt,zip,rar,gz,bz2");// ×î´óÎļþ´óСlong maxSize = 1000000;response.setContentType("text/html; charset=UTF-8");if (!ServletFileUpload.isMultipartContent(request)) {out.println(getError("ÇëÑ¡ÔñÎļþ¡£"));return null;}// ¼ì²éĿ¼File uploadDir = new File(savePath);if (!uploadDir.isDirectory()) {out.println(getError("ÉÏ´«Ä¿Â¼²»´æÔÚ¡£"));return null;}// ¼ì²éĿ¼дȨÏÞif (!uploadDir.canWrite()) {out.println(getError("ÉÏ´«Ä¿Â¼Ã»ÓÐдȨÏÞ¡£"));return null;}String dirName = request.getParameter("dir");if (dirName == null) {dirName = "image";}if (!extMap.containsKey(dirName)) {out.println(getError("Ŀ¼Ãû²»ÕýÈ·¡£"));return null;}// ´´½¨Îļþ¼ÐsavePath += dirName + "/";saveUrl += dirName + "/";File saveDirFile = new File(savePath);if (!saveDirFile.exists()) {saveDirFile.mkdirs();}SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");String ymd = sdf.format(new Date());savePath += ymd + "/";saveUrl += ymd + "/";File dirFile = new File(savePath);if (!dirFile.exists()) {dirFile.mkdirs();}FileItemFactory factory = new DiskFileItemFactory();ServletFileUpload upload = new ServletFileUpload(factory);upload.setHeaderEncoding("UTF-8");MultiPartRequestWrapper wrapper = (MultiPartRequestWrapper) request;// »ñµÃÉÏ´«µÄÎļþÃûString fileName = wrapper.getFileNames("imgFile")[0];// imgFile,imgFile,imgFile// »ñµÃÎļþ¹ýÂËÆ÷File file = wrapper.getFiles("imgFile")[0];// ¼ì²éÀÕ¹ÃûString fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();if (!Arrays.
asList(extMap.get(dirName).split(",")).contains(fileExt)) {out.println(getError("ÉÏ´«ÎļþÀÕ¹ÃûÊDz»ÔÊÐíµÄÀÕ¹Ãû¡£\nÖ»ÔÊÐí" + extMap.get(dirName)+ "¸ñʽ¡£"));return null;}// ¼ì²éÎļþ´óСif (file.length() > maxSize) {out.println(getError("ÉÏ´«Îļþ´óС³¬¹ýÏÞÖÆ¡£"));return null;}// ÖØ¹¹ÉÏ´«Í¼Æ¬µÄÃû³ÆSimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");String newImgName = df.format(new Date()) + "_"+ new Random().nextInt(1000) + "." + fileExt;byte[] buffer = new byte[1024];// »ñÈ¡ÎļþÊä³öÁ÷FileOutputStream fos;// »ñÈ¡ÄÚ´æÖе±Ç°ÎļþÊäÈëÁ÷InputStream in;try {fos = new FileOutputStream(savePath + "/" + newImgName);in = new FileInputStream(file);int num = 0;while ((num = in.read(buffer)) > 0) {fos.write(buffer, 0, num);}in.close();fos.close();} catch (FileNotFoundException e1) {e1.printStackTrace();} catch (IOException e) {e.printStackTrace();}// ·¢Ë͸ø kindeditorJSONObject obj = new JSONObject();obj.put("error", 0);obj.put("url", saveUrl + "/" + newImgName);out.println(obj.toJSONString());return null;}private String getError(String message) {JSONObject obj = new JSONObject();obj.put("error", 1);obj.put("message", message);return obj.toJSONString();}}
Kindeditor Ó Ð × Ô 'ø µäjsp íæ Æ É Ï '«demo
UploadJson: '../jsp/upload_json.jsp'
Micro? upload _ json. jsp?
List items = upload.parseRequest(request);Iterator itr = items.iterator();while (itr.hasNext()) {}
· ~~Öitr ~~~~%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% »·, ² martíã» Ó Ð · μ» ööμ, kindeditor ±? þ Î n Æ Í 'í Î ó. {%%%² %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Struts2 zookeeper  ???==jsp =±,» á¸ ä± äreqeust µäà jarí, óé HttpServletRequest ± ä³ É MultiPartRequestWrapper, when there are too many partitions parseRequest *í · μ» Ø then null
Óúlanguço ~~~~í »»
MultiPartRequestWrapper wrapper = (MultiPartRequestWrapper) request;
****************************
String fileName = wrapper.getFileNames("imgFile")[0];File file = wrapper.getFiles("imgFile")[0];
§ {******=£°
Comment 'Â {£° É {{{??' É Ï '«