Kindeditor实现图片上传(strut2版)
//*******************************************************************//////** 创建人: 何岳军////** 日 期: 2010-02-18////** 描 述: 编辑器图片上传////** 版 本: ////*******************************************************************//package eshop.action.admin;import java.util.*;import java.io.*;import javax.servlet.http.HttpServletResponse;import org.apache.struts2.ServletActionContext;import org.json.simple.JSONObject;import com.opensymphony.xwork2.*;import eshop.*;import com.dao.*;public class EditImageAdd extends ActionSupport {private String id;private String imgTitle;private String imgWidth;private String imgHeight;private String imgBorder;private List<File> imgFile;//文件private List<String>imgFileFileName; //文件名private List<String> imgFileContentType; //文件路径private String fileurl;public String getId() {return id;}public void setId(String id) {this.id = id;}public String getImgTitle() {return imgTitle;}public void setImgTitle(String imgTitle) {this.imgTitle = imgTitle;}public String getImgWidth() {return imgWidth;}public void setImgWidth(String imgWidth) {this.imgWidth = imgWidth;}public String getImgHeight() {return imgHeight;}public void setImgHeight(String imgHeight) {this.imgHeight = imgHeight;}public String getImgBorder() {return imgBorder;}public void setImgBorder(String imgBorder) {this.imgBorder = imgBorder;}public List<File> getImgFile() {return imgFile;}public void setImgFile(List<File> imgFile) {this.imgFile = imgFile;}public List<String> getImgFileFileName() {return imgFileFileName;}public void setImgFileFileName(List<String> imgFileFileName) {this.imgFileFileName = imgFileFileName;}public List<String> getImgFileContentType() {return imgFileContentType;}public void setImgFileContentType(List<String> imgFileContentType) {this.imgFileContentType = imgFileContentType;}public String getFileurl() {return fileurl;}public void setFileurl(String fileurl) {this.fileurl = fileurl;}public String execute(){try{//上传图片FileUpTool fileUpTool= new FileUpTool();for(int i=0;i<imgFile.size();i++){if(fileUpTool.saveFile(imgFile.get(i), imgFileFileName.get(i),"attached")>0){this.fileurl=fileUpTool.getFileurl();String root = ServletActionContext.getRequest().getRealPath("attached");root+="\\"; String temp = "parent.KE.plugin[\"image\"].insert(\'"+id+"','/sansui/attached/"+this.fileurl+"','"+imgTitle+"','"+imgWidth+"','"+imgHeight+"','"+imgBorder+"');"; StringBuffer sb = new StringBuffer(); sb.append("<html>"); sb.append("<head>"); sb.append("<title>Insert Image</title>"); sb.append("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">"); sb.append("</head>"); sb.append("<body>"); sb.append("<script type=\"text/javascript\">"+temp+";</script>"); sb.append("</body>"); sb.append("</html>"); String out = sb.toString(); try { PrintWriter pw = null; HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html;charset=gb2312"); response.setHeader("Cache-Control","no-cache"); //输出ajax内容 response.setHeader("Content-Type", "text/html;charset=gb2312"); response.getWriter().write(out ); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }}}return null;}catch(Exception e){e.printStackTrace();return null;}}}
<!-- 编辑器上图片上传 --><action name="adminEditImageAdd" src="/img/2012/09/23/1402264512.gif">