一、百度编辑器UEditor 下载,最好自定义下载,只取需要的功能,我下载时的版本为:1.2.0
http://ueditor.baidu.com/website/download.html
二、解压到webapp的目录ueditor里
三、修改配置文件 image.html,将默认的上传改为jsp(约97行)
url:'../../server/upload/jsp/imageUp.jsp',
四、上传的imageUp.jsp有点问题,更改如下:
//保存文件路径
String filePath = "ueditor/server/upload/uploadimages";
String realPath = request.getRealPath("/") + filePath;
String newFileName = "";
//判断路径是否存在,不存在则创建
File dir = new File(realPath);
if(!dir.isDirectory())
dir.mkdir();
if(ServletFileUpload.isMultipartContent(request)){
DiskFileItemFactory dff = new DiskFileItemFactory();
dff.setRepository(dir);
dff.setSizeThreshold(1024000);
ServletFileUpload sfu = new ServletFileUpload(dff);
FileItemIterator fii = sfu.getItemIterator(request);
String title = ""; //图片标题
String url = ""; //图片地址
String fileName = "";
String state="SUCCESS";
while(fii.hasNext()){
FileItemStream fis = fii.next();
try{
if(!fis.isFormField() && fis.getName().length()>0){
fileName = fis.getName();
Pattern reg=Pattern.compile("[.]jpg|png|jpeg|gif$");
Matcher matcher=reg.matcher(fileName);
if(!matcher.find()) {
state = "文件类型不允许!";
break;
}
newFileName = new Date().getTime()+fileName.substring(fileName.lastIndexOf("."),fileName.length());
url = realPath+"/"+ newFileName;
BufferedInputStream in = new BufferedInputStream(fis.openStream());//获得文件输入流
FileOutputStream a = new FileOutputStream(new File(url));
BufferedOutputStream output = new BufferedOutputStream(a);
Streams.copy(in, output, true);//开始把文件写到你指定的上传文件夹
}else{
String fname = fis.getFieldName();
if(fname.indexOf("pictitle")!=-1){
BufferedInputStream in = new BufferedInputStream(fis.openStream());
byte c [] = new byte[10];
int n = 0;
while((n=in.read(c))!=-1){
title = new String(c,0,n);
break;
}
}
}
}catch(Exception e){
e.printStackTrace();
}
}
title = title.replace("&", "&").replace("'", "&qpos;").replace("\"", """).replace("<", "<").replace(">", ">");
response.getWriter().print("{'url':'uploadimages/"+newFileName+"','title':'"+title+"','state':'"+state+"'}");
}

- 大小: 8.6 KB
分享到:
相关推荐
本站源码使用 J2EE 开发; 使用 Spring4+Springmvc+Mybatis3 架构, 采用 Mysql 数据库; 使用 Maven3 管理项目,使用 Shiro...在线编辑器使用了百度的 UEditor,支持单图,多图上传,支持截图上传,支持代码高亮特性;
知识库的内容编辑依赖于百度的ueditor富文本编辑器 05 security 提供一套图片验证码,邮箱验证码的功能(图片验证码使用百度服务,本地版本计划中,暂未实现,) (已废弃)06 log 这个工程的原本目标是为系统的所有...
1)替换编辑器为UEditor 2)支持站点资源相对路径模式 3) 数据展示图更换为echarts 4)提升广告模块在广告拦截软件下的表现 5) 优化模型内容维护页面交互 6)修复若干BUG JTopCMS特点 1.支持集群管理 系统...
1)替换编辑器为UEditor 2)支持站点资源相对路径模式 3) 数据展示图更换为echarts 4)提升广告模块在广告拦截软件下的表现 5) 优化模型内容维护页面交互 6)修复若干BUG JTopCMS特点 1.支持集群管理 系统...
- **CKEditor 3.6/UEditor**:支持富文本编辑功能。 - **JQuery 1.8**:提供了丰富的JavaScript功能。 - **CXF 2.0**:支持Web Services,增强了系统的集成能力。 - **Alfresco Activiti 5.8**:提供了一个高...