仅作为入门测试。。。。。。

下载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 编辑器整合入门的更多相关文章

  1. Spring MVC -- UEditor 编辑器整合 上传图片至外部文件夹(非项目文件夹)

    上传图片到外部储存,回显图片 下载全部UEditor资源源码 config.json配置 config.json中添加如下属性 (一定要添加此属性): "physicsPath": ...

  2. 【FreeMarker】Spring MVC与FreeMarker整合(二)

    前一篇介绍了FreeMarker的基本使用,本例介绍Spring MVC与FreeMarker整合 不熟悉项目搭建,可参考 [FreeMarker]FreeMarker快速入门(一) 整合 1.新建S ...

  3. 转载 Spring、Spring MVC、MyBatis整合文件配置详解

    Spring.Spring MVC.MyBatis整合文件配置详解   使用SSM框架做了几个小项目了,感觉还不错是时候总结一下了.先总结一下SSM整合的文件配置.其实具体的用法最好还是看官方文档. ...

  4. Spring MVC、MyBatis整合文件配置详解

    Spring:http://spring.io/docs MyBatis:http://mybatis.github.io/mybatis-3/ Building a RESTful Web Serv ...

  5. 调试SPRING MVC(或者整合SSH)的时候遇到了org/objectweb/asm/Type

    调试SPRING MVC(或者整合SSH)的时候遇到了org/objectweb/asm/Type 解决方法1: 原因是Spring中的cglib-nodep-2.x.x.jar与Hibernate中 ...

  6. Mybaits-从零开始-Spring、Spring MVC、MyBatis整合(未万待续)

    Spring.Spring MVC.MyBatis整合(未万待续)

  7. spring mvc:ueditor跨域多图片上传失败解决方案

    公司在开发一个后台系统时需要使用百度的UEditor富文本编辑器,应用的场景如下: UEditor的所有图片.js等静态资源在一个专有的静态服务器上: 图片上传在另外一台服务器上: 因为公司内部会使用 ...

  8. spring mvc 自定义编辑器

    起始知识: Java标准的PropertyEditor的核心功能是将一个字符串转换为一个Java对象,以便根据界面的输入或配置文件中的配置字符串构造出一个JVM内部的java对象. 如何注册自定义的属 ...

  9. Spring + Spring MVC + MyBatis框架整合

    ---恢复内容开始--- 一.Maven Web项目创建 如有需要,请参考:使用maven创建web项目 二.Spring + Spring MVC + MyBatis整合 1.Maven引入需要的J ...

随机推荐

  1. Centos6.6 系统优化

    1:最小化安装 2:修改网卡 vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0HWADDR=52:54:00:0e:c2:c3TYPE ...

  2. [luogu]P4316 绿豆蛙的归宿(拓扑排序,期望)

    P4316 绿豆蛙的归宿 题目背景 随着新版百度空间的上线,Blog宠物绿豆蛙完成了它的使命,去寻找它新的归宿. 题目描述 给出一个有向无环图,起点为1终点为N,每条边都有一个长度,并且从起点出发能够 ...

  3. Informatica环境搭建过程中一些问题-近期项目进了新人,在搭建环境中存在一些问题,之前都处理过一直没有整理,这次接着机会,把这些常见问题处理整理出来

    一.Informatica9.5.1创建资源库出错找不到libpmora8.so 错误如下: Database driver event...Error occurred loading librar ...

  4. DM8168 屏蔽 PCIe

    DM8168新板在没有做PCI接口的情况下,能够把PCI模块凝视,直接尝试: make CROSS_COMPILE=arm-none-linux-gnueabi- ARCH=arm menuconfi ...

  5. POJ 2516 Minimum Cost (最小费用最大流)

    POJ 2516 Minimum Cost 链接:http://poj.org/problem?id=2516 题意:有M个仓库.N个商人.K种物品.先输入N,M.K.然后输入N行K个数,每一行代表一 ...

  6. bzoj1430: 小猴打架(prufer序列)

    1430: 小猴打架 题目:传送门 简要题意: n只互不相识的猴子打架,打架之后就两两之间连边(表示已经相互认识),只有不认识(朋友的朋友都是朋友)的两只猴子才会打架.最后所有的猴子都会连成一棵树,也 ...

  7. 7. 关于IntelliJ IDEA删除项目

    转自:https://www.cnblogs.com/zhangqian27/p/7698148.html 刚开始使用IDEA . 自己创建项目玩,结果发现IDEA无法删除,我也是醉了,Eclipse ...

  8. IE11 mobile 的 UA(User-Agent)

    如果您在 IE11 mobile 上获得的 UA(User-Agent) 是 Mozilla/5.0 (Mobile; Linux; Android 4.2; Microsoft Build/Virt ...

  9. RSA加密的方式和解密方式

    RSAsecurity.java package com.mstf.rsa; import java.security.KeyFactory; import java.security.KeyPair ...

  10. 【AngularJS学习笔记】AngularJS表单验证

    AngularJS表单验证 AngularJS提供了一些自带的验证属性 1.novalidate:添加到HTML的表单属性中,用于禁用浏览器默认的验证. 2.$dirty   表单有填写记录 3.$v ...