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

下载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. CentOS7 安装 MySQL 5.7

    wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz yum -y ...

  2. JAVA jsp page指令的属性 errorPage 和isErrorPage

    >errorPage指定当前页面出现错误的实际响应页面是什么, 其中“/” 表示的是当前WEB应用的根目录 <% page errorPage="/error.jsp" ...

  3. Hololens官方教程精简版 - 08. Sharing holograms(共享全息影像)

    前言 注意:本文已更新到5.5.1f1版本号 本篇集中学习全息影像"共享"的功能,以实如今同一房间的人,看到"同一个物体".之所以打引號,是由于.每一个人看到的 ...

  4. Ubuntu搜狗输入法的安装

    Ubuntu搜狗输入法的安装 这个直接安装就可以了:因为现在的Ubuntu是16.04版本,输入法已经是Fcitx版本: 下载搜狗输入法For Linux之后,直接双击就可以安装了: 安装之后,需要注 ...

  5. 一、奇妙插件Tampermonkey的简单安装教程

    奇妙插件Tampermonkey的简单安装教程 1.下载 对于浏览器而言,一般的功能并不能满足"特殊用户的需求".这时候就须要插件来帮忙了.那么讲到插件的支持多又常见的浏览器必定要 ...

  6. Numpy科学计算工具

    Numpy初探 Numpy基础数据结构 Numpy数组是一个多维数组,称为ndarray.其由两部分组成: 实际的数据 描述这些数据的原数据 导入该库: import numpy as np 多维数组 ...

  7. List operations

    The + operator concatenates lists: Similarly, the * operator repeats a list a given number of items: ...

  8. laravel中的数据迁移和数据填充

    laravel中的数据迁移和数据填充 标签(空格分隔): php 生成迁移文件两种方式: 1 新建一个表的迁移文件 php artisan make:migration create_students ...

  9. 8.变量内存CPU原理

    编译器先明确是什么类型,然后明确变量名,变量表管理所有的变量,不在变量表内部的变量不能引用.每个变量对应一整块内存 a+1所计算出来的值在寄存器中,只有变量可以被赋值,变量必须在内存里面 c语言内嵌汇 ...

  10. C#中Request.Cookies 和 Response.Cookies 的区别分析

    .NET中提供了读写Cookie的多种方法,Request.Cookies 是客户端通过 Cookie 标头形式由客户端传输到服务器的 Cookie:Response.Cookies 在服务器上创建并 ...