<script type="text/javascript">
//富文本编辑器初始化
$('#msgWriteAddMsgContent').xheditor({tools:'mini', html5Upload:false,
upMultiple:'1',upImgUrl:"/msg/msgWriteUploadImage.action",
upImgExt:"jpg,jpeg,gif,png",onUpload:insertUpload});
function insertUpload(arrMsg){
console.log(arrMsg);
var i,msg;
for(i=0;i<arrMsg.length;i++)
{
msg=arrMsg[i];
$("#xheImgUrl").append(msg);
$("#imageUrl").attr("value",msg);
}
}
</script>
<textarea id="msgWriteAddMsgContent" name="msgContent" cols="61" rows="14" style="width: 550px" maxlength="1000"></textarea>
在某些情况下xheditor编辑器在第一次可以编辑,但是第二次的时候不能编辑,比如用jquery-UI弹窗中的编辑器就可能会出现此问题,解决方法是在关闭弹窗时用
$(
"#elm"
).xheditor(
false
);将xheditor编辑器删除,下次弹窗时重新加载
public void msgWriteUploadImage(){
if (null!=filedata) {
try {
long fileName=System.currentTimeMillis();
String uploadPath = ServletActionContext.getServletContext().getRealPath("/");//项目在tomcat服务器本地部署路径,文件需要有硬盘绝对路径才可存放,并不是workspace的路径
InputStream is=new FileInputStream(filedata);
File outFile = new File(uploadPath+"/uploadImg/"+fileName+".jpg");// 输出文件
String outPathString=outFile.getAbsolutePath();
System.out.println(uploadPath+"/uploadImg/");
OutputStream os = new FileOutputStream(outFile);
byte[] buffer = new byte[1024];
int len = 0;
while ((len=is.read(buffer))!=-1) {
os.write(buffer,0,len);
}
is.close();
os.close();
response.setCharacterEncoding("utf-8");
PrintWriter out=response.getWriter();
out.println("{'err':'','msg':'"+request.getContextPath()+"/uploadImg/"+fileName+".jpg'}");//取项目相对路径
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}else {
PrintWriter out;
try {
response.setCharacterEncoding("utf-8");
out = response.getWriter();
out.println("{'err':'上传文件为空!!','msg':''}");
} catch (IOException e) {
e.printStackTrace();
}
}
}