Spring MVC -- UEditor 编辑器整合入门
仅作为入门测试。。。。。。
使用maven项目
<!-- 上传文件的支持 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<!-- org.json -->
<!--JSON is a light-weight, language independent, data interchange format. See http://www.JSON.org/-->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160212</version>
</dependency>
在此我将它们都放在/webapp/static/UEditor-jsp目录下,进行搞事情,毕竟需要弄清楚路径的配置。
新增jsp页面
<script src="/static/UEditor-jsp/ueditor.config.js"></script>
<script src="/static/UEditor-jsp/ueditor.all.min.js"></script>
<script src="/static/UEditor-jsp/lang/zh-cn/zh-cn.js"></script> <script id="container" name="content" type="text/plain">测试编辑器。。。</script>
<script type="text/javascript">
var editor = UE.getEditor('container');
</script>
修改 ueditor.config.js 服务器请求接口路径
默认请求地址为jsp/controller.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
import="com.baidu.ueditor.ActionEnter"
pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<% request.setCharacterEncoding( "utf-8" );
response.setHeader("Content-Type" , "text/html"); String rootPath = application.getRealPath( "/" ); out.write( new ActionEnter( request, rootPath ).exec() ); %>
请求地址改为springMVC的请求路径,基本完全照搬翻译。
@Controller
@RequestMapping("/uEditor")
public class UEditorController { @RequestMapping(value = "/config")
public void config(HttpServletRequest request, HttpServletResponse response) {
response.setContentType("application/json");
// String rootPath = request.getSession()
.getServletContext().getRealPath("/"); 修改如下
String rootPath = request.getSession()
.getServletContext().getRealPath("/static/UEditor-jsp");
try {
String exec = new ActionEnter(request, rootPath).exec();
PrintWriter writer = response.getWriter();
writer.write(exec);
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
如下是获取config.json 配置的方式
ConfigManager
跟踪代码
String exec = new ActionEnter(request, rootPath).exec(); -----> this.configManager = ConfigManager.getInstance( this.rootPath, this.contextPath, request.getRequestURI() ); -----> private ConfigManager ( String rootPath, String contextPath, String uri ) throws FileNotFoundException, IOException { rootPath = rootPath.replace( "\\", "/" ); this.rootPath = rootPath;
this.contextPath = contextPath; // 路径会稍有不一样,请各自调试查看
if ( contextPath.length() > 0 ) {
this.originalPath = this.rootPath + uri.substring( contextPath.length() );
} else {
this.originalPath = this.rootPath + uri;
} this.initEnv(); } ------> initEnv() ------> private void initEnv () throws FileNotFoundException, IOException { File file = new File( this.originalPath ); if ( !file.isAbsolute() ) {
file = new File( file.getAbsolutePath() );
} this.parentPath = file.getParent(); String configContent = this.readFile( this.getConfigPath() );
// 此处再次进行路径更改获取到的是 parent try{
JSONObject jsonConfig = new JSONObject( configContent );
this.jsonConfig = jsonConfig;
} catch ( Exception e ) {
this.jsonConfig = null;
} }
最后根据返回的路径将config,json 移动到相应的目录,此处根据个人情况特殊进行操作。
在此就可以进行图片的上传了。
不过还需要修改配置中的路径配置,否则会上传成功却不能显示。
默认路径:
修改如下,主要修改 imageUrlPrefix imagePathFormat
Spring MVC -- UEditor 编辑器整合入门的更多相关文章
- Spring MVC -- UEditor 编辑器整合 上传图片至外部文件夹(非项目文件夹)
上传图片到外部储存,回显图片 下载全部UEditor资源源码 config.json配置 config.json中添加如下属性 (一定要添加此属性): "physicsPath": ...
- 【FreeMarker】Spring MVC与FreeMarker整合(二)
前一篇介绍了FreeMarker的基本使用,本例介绍Spring MVC与FreeMarker整合 不熟悉项目搭建,可参考 [FreeMarker]FreeMarker快速入门(一) 整合 1.新建S ...
- 转载 Spring、Spring MVC、MyBatis整合文件配置详解
Spring.Spring MVC.MyBatis整合文件配置详解 使用SSM框架做了几个小项目了,感觉还不错是时候总结一下了.先总结一下SSM整合的文件配置.其实具体的用法最好还是看官方文档. ...
- Spring MVC、MyBatis整合文件配置详解
Spring:http://spring.io/docs MyBatis:http://mybatis.github.io/mybatis-3/ Building a RESTful Web Serv ...
- 调试SPRING MVC(或者整合SSH)的时候遇到了org/objectweb/asm/Type
调试SPRING MVC(或者整合SSH)的时候遇到了org/objectweb/asm/Type 解决方法1: 原因是Spring中的cglib-nodep-2.x.x.jar与Hibernate中 ...
- Mybaits-从零开始-Spring、Spring MVC、MyBatis整合(未万待续)
Spring.Spring MVC.MyBatis整合(未万待续)
- spring mvc:ueditor跨域多图片上传失败解决方案
公司在开发一个后台系统时需要使用百度的UEditor富文本编辑器,应用的场景如下: UEditor的所有图片.js等静态资源在一个专有的静态服务器上: 图片上传在另外一台服务器上: 因为公司内部会使用 ...
- spring mvc 自定义编辑器
起始知识: Java标准的PropertyEditor的核心功能是将一个字符串转换为一个Java对象,以便根据界面的输入或配置文件中的配置字符串构造出一个JVM内部的java对象. 如何注册自定义的属 ...
- Spring + Spring MVC + MyBatis框架整合
---恢复内容开始--- 一.Maven Web项目创建 如有需要,请参考:使用maven创建web项目 二.Spring + Spring MVC + MyBatis整合 1.Maven引入需要的J ...
随机推荐
- [NOIP2012提高组]疫情控制
题目:洛谷P1084.codevs1218.Vijos P1783. 题目大意:有一棵n个节点的,根为1的带权树和m支军队.每支军队可以在一个点上停下,那么从1开始就不能经过这个点了.现在有m支军队已 ...
- vue-cli#2.0项目结构分析
项目结构 build 构建工具相关的目录 config 配置目录 dist 通过工具打包生成的最终需要上线的目录 node_modules 存放本地开发所有的依赖包的目录 src 源码目录 stati ...
- 【BZOJ 1257】[CQOI2007]余数之和
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] k%i=k-(k/i)i 则∑k%i = nk-∑(k/i)*i 因为k/i是整除运算. 所以会有某一段连续的i,它们的k/i的值都 ...
- code vs 1216 跳马问题
1216 跳马问题 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 题目 输入描述 Input Descri ...
- hdoj-1212-Big Number【大数取余&简单题】
Big Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- springMVC 配置jdbcTemplate连接Oracle数据库出错
springMVC 配置jdbcTemplate连接Oracle数据库出错 错误信息: log4j:WARN No appenders could be found for logger (org.s ...
- 2014 百度之星 1003 题解 Xor Sum
Xor Sum Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包括了N个正整数,随后 Prometheu ...
- SQL Server 2008 备份数据库
1.打开SQL , 找到要备份的数据库 , 右键 >> 任务 >>备份 2.弹出 [ 备份数据库对话框 ] ,如图: 3.点击加入 [ button ] . 例如以下图: 4. ...
- angularjs 指令2
<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...
- Python TurtleWorld configuration and simple test
TurtleWorld provides a set of functions for drawing lines by steering turtles around the screen. You ...