UEditor Java版更改上传文件路径
来源:互联网 发布:进入telnet端口命令 编辑:程序博客网 时间:2024/06/06 03:54
宽为限 紧用功 功夫到 滞塞通
玩过UEditor的大家应该都遇到过这样的问题,哈哈,终于把它放到项目上去了,编辑图片上传附件啥的挺爽的。后来突然发现显示页面不显示上传的图片了,去上传目录一看,刚刚上传的东西全没了。。。这就尴尬了
没错是重启tomcat服务的时候被tomcat给清理了,这样的话我们就不能把上传的资源放到tomcat运行的项目目录下了。问题是 config.json 文件里配的路径都是相对路径,都配置到项目上的,所以改这个是不行的了。那我们只能更改它上传文件用的 java文件也就是controller.jsp文件里的 ActionEnter,我们给他重写一下,把路径改为自己指定的路径。
重写的代码如下
package cn.lovelyc.soluser.official.util.ueditor;import com.baidu.ueditor.ActionEnter;import com.baidu.ueditor.ConfigManager;import com.baidu.ueditor.define.ActionMap;import com.baidu.ueditor.define.AppInfo;import com.baidu.ueditor.define.BaseState;import com.baidu.ueditor.define.State;import com.baidu.ueditor.hunter.FileManager;import com.baidu.ueditor.hunter.ImageHunter;import com.baidu.ueditor.upload.Uploader;import javax.servlet.http.HttpServletRequest;import java.util.Map;public class UeditorActionEnter extends ActionEnter { private HttpServletRequest request = null; private String rootPath = null; private String contextPath = null; private String actionType = null; private ConfigManager configManager = null; public UeditorActionEnter(HttpServletRequest request, String rootPath) { super(request, rootPath); this.request = request; this.rootPath = rootPath; this.actionType = request.getParameter("action"); this.contextPath = request.getContextPath(); this.configManager = ConfigManager.getInstance(this.rootPath, this.contextPath, request.getRequestURI()); } @Override public String invoke() { if (actionType == null || !ActionMap.mapping.containsKey(actionType)) { String jsonString = new BaseState(false, AppInfo.INVALID_ACTION).toJSONString(); return jsonString; } if (this.configManager == null || !this.configManager.valid()) { String jsonString = new BaseState(false, AppInfo.CONFIG_ERROR).toJSONString(); return jsonString; } State state = null; int actionCode = ActionMap.getType(this.actionType); Map<String, Object> conf = null; switch (actionCode) { case ActionMap.CONFIG: String string = this.configManager.getAllConfig().toString(); return string; case ActionMap.UPLOAD_IMAGE: case ActionMap.UPLOAD_SCRAWL: case ActionMap.UPLOAD_VIDEO: case ActionMap.UPLOAD_FILE: conf = this.configManager.getConfig(actionCode); //注意再这里修改rootPath和savePath,上传的实际路径为rootPath+savePath conf.put("rootPath", "/soluser/official/"); conf.put("savePath", "/upload/" + conf.get("savePath")); state = new Uploader(request, conf).doExec(); break; case ActionMap.CATCH_IMAGE: conf = configManager.getConfig(actionCode); //注意再这里修改rootPath和savePath,上传的实际路径为rootPath+savePath conf.put("rootPath", "/soluser/official/"); conf.put("savePath", "/upload/" + conf.get("savePath")); String[] list = this.request.getParameterValues((String) conf.get("fieldName")); state = new ImageHunter(conf).capture(list); break; case ActionMap.LIST_IMAGE: case ActionMap.LIST_FILE: conf = configManager.getConfig(actionCode); //注意再这里修改rootPath和savePath,上传的实际路径为rootPath+savePath conf.put("rootPath", "/soluser/official/"); conf.put("savePath", "/upload/" + conf.get("savePath")); conf.put("dir", conf.get("dir")); int start = this.getStartIndex(); state = new FileManager(conf).listFile(start); break; } return state.toJSONString(); }}
controller.jsp 这里也跟着改
<%@ page language="java" contentType="text/html; charset=UTF-8" import="cn.lovelyc.soluser.official.util.ueditor.UeditorActionEnter" pageEncoding="UTF-8"%><%@ page trimDirectiveWhitespaces="true" %><% request.setCharacterEncoding( "utf-8" ); response.setHeader("Content-Type" , "text/html"); String rootPath = application.getRealPath( "/" ); out.write( new UeditorActionEnter( request, rootPath ).exec() );%>
config.json
"imageUrlPrefix": "/soluser/official", /* 图片访问路径前缀 */"imagePathFormat": "/describe/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
注意:访问路径前缀一定要加哦!
上传图片试试
这里回显是报错了,404。我们看看它实际上传成功没
我们发现它是根据你重写的路径+imagePathFormat 配置路径格式是保存了的。嗯,保存到这里的话就不怕被tomcat给清理掉了,but我们怎么获取到实际磁盘路径下的文件呢?
对了,我们可以在tomcat的配置文件里加一个路径映射 \(^o^)/YES!
修改tomcat conf目录下的 server.xml文件。
look
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true"> ... <!-- 本地磁盘映射 --> <Context path="/soluser/official" docBase="D:\soluser\official"></Context></Host>
OK!我们再重启试试
哈哈,你的小阔爱已上线!
站在巨人的肩膀上
本篇博文参考的文章
http://blog.csdn.net/littlebirdofjava/article/details/53945416
http://blog.csdn.net/xiaoyu19910321/article/details/51363679
http://blog.csdn.net/sinat_34803353/article/details/53292284?locationNum=3&fps=1
http://www.bubuko.com/infodetail-1142341.html
- ueditor Java版更改上传文件路径
- UEditor Java版更改上传文件路径
- ueditor Java版更改上传文件路径
- [转] ueditor Java版更改上传文件路径
- ueditor 更改上传文件的路径
- UEditor图片上传文件路径
- UEditor自定义上传和读取文件路径
- .net下的ueditor更改上传路径为绝对路径
- ueditor上传视频控件,如何获得上传文件的路径?
- Ueditor 上传路径修改
- Ueditor上传路径问题
- ueditor上传路径问题
- ueditor 上传文件到ftp java
- PHP实现文件上传,更改路径,文件名
- UEditor 1.4.2+版本文件图片上传路径配置
- 百度编辑器ueditor上传图片及文件路径配置
- 修改ueditor的上传文件、图片、视频等路径
- 解决ueditor上传文件到tomcat虚拟路径等问题
- python 变量前的 单下划线 双下划线
- VB.Net 中实现延迟的几种方法分析
- Java中static变量作用和用法详解
- 读书笔记_大话数据结构第九章_排序
- webpack搭建简单的多页面应用
- UEditor Java版更改上传文件路径
- 自定义View之小球自由落体弹跳加载控件
- 实现表格冻结顶栏效果
- NOIP2012普及组-寻宝
- 高一暑假集训总结
- 2017ccpc网络赛 1003Friend-Graph
- oracle简单归纳
- 读书笔记_CLR.via.c#第十六章_数组
- XRecyclerview用法以及遇到的一些问题