xhEditor具备在编辑框中插入图片和音频,但是默认情况时关闭的,可以通过如下形式来实现在编辑框中插入图片并显示在编辑框中。下面实现利用struts上传图片,需要注意的是xhEditor上传图片时参数名为filedata。
1、JSP页面
<textarea class="xheditor {upBtnText:'浏览',upImgUrl:'uploadAction!uploadImg',upImgExt:'jpg,jpeg,gif,png'}"></textarea>
2、action
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletContext;
import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Component;
import com.opensymphony.xwork2.ActionSupport;
@Component("uploadAction")
public class UploadAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 7087202718619368736L;
private File filedata;
private String filedataFileName;
private String filedataContentType;
public void uploadImg() {
ServletContext sc = ServletActionContext.getServletContext();System.out.println(sc.getContextPath());
if(filedata!=null){
String dataDir = sc.getRealPath("/images/upload");
String fileType = filedataFileName.substring(filedataFileName.lastIndexOf("."));
int na = (int)(Math.random() * 9999.0D);
String tempName = new Long(System.currentTimeMillis()).toString() + String.valueOf(na) + fileType;
File savedFile = new File(dataDir, tempName);
filedata.renameTo(savedFile);
tempName = sc.getContextPath() + "/images/upload/" + tempName;
try {
PrintWriter out = ServletActionContext.getResponse().getWriter();
out.print("{\"err\":\"\",\"msg\":\"" + tempName + "\"}");
out.flush();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public File getFiledata() {
return filedata;
}
public void setFiledata(File filedata) {
this.filedata = filedata;
}
public String getFiledataFileName() {
return filedataFileName;
}
public void setFiledataFileName(String filedataFileName) {
this.filedataFileName = filedataFileName;
}
public String getFiledataContentType() {
return filedataContentType;
}
public void setFiledataContentType(String filedataContentType) {
this.filedataContentType = filedataContentType;
}
}
分享到:
相关推荐
博文参考地址:http://blog.csdn.net/itmyhome1990/article/details/38495623
至少尝试了10个在线编辑器才选出了的这个,支持本地图片插入,里面自己写了个java版本的ajax处理。
基于轻量级的JQuery的xheditor编辑器+jsp实现图上传功能
xheditor-1.2.1 上传图片 jquery版本:jquery-1.11.0 ASP.NET环境
方法2:利用xhEditor提供的jQuery插件接口来实现对特定textarea的初始化和传递参数,例: $('#elm1').xheditor(); 或者 $('#elm1').xheditor({tools:'mini'}); 特别说明:两种初始化方法只能选择其中一种使用,如果...
参考博文:http://blog.csdn.net/itmyhome1990/article/details/38491205
在xheditor在线编辑器下,ASP提交远程图片自动上传到服务器
1 .修改多处引用 每次都要手动的写入大量的JS 2 .统一上传路径 3 .上传的文件信息保存到数据库 且返回文件Id 及...增加Google地图 插入图片 5 .上传附件及Google地图 为自定义的插件开发 使用 C# 语言的可以关注下
xheditor jsp完整实例 根据 http://xheditor.com/ 官网开发的jsp版本的实例、 部署即可运行。 希望网友们喜欢。
xheditor-1.1.4 在线编辑器 自己感觉很不错!
xheditor-1.1.14.zip
xheditor-1.2.2.zip
xhEditor可以在您的CMS、博客、论坛、商城等互联网平台上完美的嵌入运行,能够非常灵活简单的和您的系统实现完美的无缝衔接。 自2009年4月首个版本发布以来,凭借我们人性化的用户体验和不断持续完善的态度,越来越...
xhEditor在线编辑器完整实例,可直接运行
xheditor完整实例,下载即可用,copy一下
集成xheditor,loadmask和requireJS完成的通过JQuery异步提交数据到服务器的代码
最新版本xheditor-v1.2.2
xheditor.js源码,来自网上。xheditor.js源码,来自网上。
xheditor1.1.13在ASPNET开发网站中的使用,C#,vs2013,实现在线编辑html流,包括本地图片的上传,非常简洁,稍加扩充可用于自己的网站(如博客网站等) 本例xheditor控件采用自定义模式,可参照进行重新配置,实现控件的增减,...
xheditor-1.1.6,html编辑器