String id = (String) request.getParameter("id");
String imgTitle = (String) request.getParameter("imgTitle");
String imgWidth = (String) request.getParameter("imgWidth");
String imgHeight = (String) request.getParameter("imgHeight");
String imgBorder = (String) request.getParameter("imgBorder");
String url = "";
String out = "";
Hashtable files = this.getMultipartRequestHandler().getFileElements();
for (Map.Entry<String, FormFile> entry : (Set<Map.Entry<String, FormFile>>) (files.entrySet())) {
FormFile ff = entry.getValue();
String name = ff.getFileName();
if (StringUtils.isEmpty(name)) {
out=this.alert("请选择文件。");
}
if(!StringUtils.isEmpty(name)&&!ImageUtils.isPicFile(name))
{
out=this.alert("上传文件扩展名是不允许的扩展名。");
}
if (!StringUtils.isEmpty(name)&&ImageUtils.isPicFile(name)) {
String img_format = "." + StringUtils.split(name, '.')[1];
Pic pic = new Pic();
String picName = "";
try {
picName = this.photoService.uppic(this.getUserSession().getUid(), img_format, ff.getInputStream());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
out=this.alert("请选择文件。");
} catch (IOException e) {
// TODO Auto-generated catch block
out=this.alert("上传文件失败。");
}
pic.setFilename(picName);
pic.setFilepath("");
pic.setDateline(new Date());
pic.setUid(this.getUserSession().getUid());
url = Constants.PHOTOS_PATH + pic.getUid() + "/" + ImageUtils.getUserMidPic(pic);
String temp = "parent.KE.plugin[\"image\"].insert(\'"+id+"','"+url+"','"+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>");
out = sb.toString();
}
}
try {
//输出ajax内容
response.setHeader("Content-Type", "text/html;charset=UTF-8");
response.getWriter().write(out );
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}