去官网下载http://xheditor.com/
新建index.jsp 代码如下<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
basePath = basePath.substring(0, (basePath.lastIndexOf("/") == basePath.length() - 1) ? basePath.lastIndexOf("/") : basePath.length());
session.setAttribute("basePath",basePath+"/");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="${basePath }js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="${basePath }xheditor/xheditor-1.1.13-zh-cn.min.js"></script>
</head>
<body>
<textarea id="elm1" name="content" style="width: 600px;height: 400px;">test</textarea>
</body>
<script type="text/javascript">
jQuery(document).ready(function(){
/**
***/
var editors=$('#elm1').xheditor({tools:'Cut,Copy,Img,Fullscreen,Emot',
html5Upload:false,
upImgUrl:"${basePath}/editor/editor.action",
upImgExt:"jpg,jpeg,gif,png",
upMultiple:false,
onUpload:insertUpload
});
//$('#elm1').xheditor(false);卸载编辑器
/*jQuery("#ee").click(function(){
alert(editors.getSource());//获取编辑器数据
});*/
});
function insertUpload(arrMsg){
var i,msg;
for(i=0;i<arrMsg.length;i++)
{
msg=arrMsg[i];
//alert(msg);
}
}
</script>
</html>
然后新建TestAction 代码如下
package com.test;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import net.sf.json.util.JSONUtils;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.json.JSONUtil;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
public class TestAction extends BaseAction{
private File filedata;
public String editor(){
System.out.println(filedata+"哈哈哈哈");
String path=ServletActionContext.getServletContext().getRealPath("e");
long time=System.currentTimeMillis();
String imagePath = path+"\\"+time+".jpg";//大图片路径
try {
if(filedata!=null){
FileUtils.copyFile(filedata, new File(imagePath));
System.out.println("dddddd");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//PrintWriter p=null;
String err="";
System.out.println(imagePath);
String imagePath2=this.getBasePath()+File.separator+"\\e\\"+File.separator+time+".jpg";
String newFileName=time+".jpg";
//this.printMessage("{\"err\":\"\",\"msg\":\""+imagePath+"\"} ");
this.printMessage("{\"err\":\"" + err + "\",\"msg\":\"" + imagePath2+ "\"}");
// p.print("{\"err\":\"\",\"msg\":\"200906030521128703.gif\"} ");
return null;
}
public File getFiledata() {
return filedata;
}
public void setFiledata(File filedata) {
this.filedata = filedata;
}
}
配置文件 struts。xml 我想只要稍微有点基础的人都能配置出来