最近再弄富文本框,选择了UEditor,原因是:界面漂亮,百度开源的
然而,

开启整合之路(怎么做)

1.下载插件

下载只有将插件放在Webapp下,如图

2、修改

导入之后我们就需要修改一些参数已满足我们的需求。如图

我们要修改图片的保存路径,因为插件默认是保存在项目部署的路径下,每次重新部署图片都会消失,所以我们需要将图片单独保存到一个图片服务器下,展示图片的controller如下

@RequestMapping(value = "/showImage")
public void showImage(HttpServletRequest request, HttpServletResponse response,String filePath){
String rootPath=request.getSession().getServletContext().getRealPath("/");
String absolutePath=rootPath+filePath;
//截取文件后缀名
String suffix=absolutePath.substring(absolutePath.lastIndexOf(".")+1);
String responseType = "image/jpeg";
if ("png".equals(suffix)) {
responseType = "image/png";
} else if ("jpg".equals(suffix) || "jpeg".equals(suffix)) {
responseType = "image/jpeg";
} else if ("gif".equals(suffix)) {
responseType = "image/gif";
}
response.setContentType(responseType);
FileInputStream inputStream=null;
OutputStream os=null;
try {
int count;
inputStream=new FileInputStream(absolutePath);
os=response.getOutputStream();
byte[] buffer=new byte[1024*1024];
while ((count=inputStream.read(buffer))!=-1){
os.write(buffer,0,count);
} }catch (IOException ex){
logger.error("图片找不到{}",ex);
}finally {
if (inputStream!=null){
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (os!=null){
try {
os.flush();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} }

如果不想改的话我们这样就弄好了,由于我的项目用的springMVC,如果你在web.xml那边的配置如图

多图上传时有可能会碰到弹出框不能显示的问题
因为弹出框的静态资源是image.html,这个image.html没有对应的controller的话,被DispatcherServlet拦截之后,就会找不到controller,然后就会抛出404的错误,目前暂时的处理办法是,修个image.html的后缀为htm,使其不被拦截。

3.使用

前台使用

<script type="text/javascript" src="../static/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="../static/ueditor/ueditor.all.js"></script> <input type="hidden" class="span12 required" name="info" id="info" value='${mallProduct.info}' />
<script id="editor" type="text/plain" style="width:96%;height:300px;" class="required"></script> var ue = UE.getEditor('editor');
ue.ready(function() {
ue.setContent($("#info").val());
});

相关的代码结构以及原理

UEditor的上传功能是在controller.jsp中实现的

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.baidu.ueditor.ActionEnter" %>
<%@ page trimDirectiveWhitespaces="true" %>
<% request.setCharacterEncoding( "utf-8" );
response.setHeader("Content-Type" , "text/html"); String rootPath = application.getRealPath( "/" ); out.write( new ActionEnter( request, rootPath ).exec() ); %>

入口在ueditor.config.js中。
=========================================================================

完美的分割线

如果你觉得用controller.jsp作为上传服务不妥的话,我们也可以修改将上传代码放入Controller中
代码如下:

package com.lyz.controller;

import com.baidu.ueditor.ActionEnter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter; /**
* Created by xiangwei on 2017/7/16.
*/
@Controller
@RequestMapping("/ueditor")
public class UeditorController {
private Logger logger= LoggerFactory.getLogger(UeditorController.class);
@RequestMapping(value = "/dispatch")
public void config(HttpServletRequest request, HttpServletResponse response) {
response.setContentType("application/json");
String rootPath = request.getSession().getServletContext().getRealPath("/");
response.setHeader("Content-Type" , "text/html");
try {
String exec = new ActionEnter(request, rootPath).exec();
PrintWriter writer = response.getWriter();
writer.write(exec);
writer.flush();
writer.close();
} catch (IOException e) {
logger.error("图片上传失败!");
e.printStackTrace();
} } }

然后修改ueditor.config.js文件中的

再修改ConfigManager类的getConfigPath()方法,将路径指定到config.json的路径。

如:

private String getConfigPath () {
// return this.parentPath + File.separator + ConfigManager.configFileName;
return this.rootPath+File.separator+"static/ueditor/"+"jsp"+File.separator+ConfigManager.configFileName;
}

UEditor使用总结(与SpringMVC整合)的更多相关文章

  1. springMVC -- 整合UEditor(富文本编辑器)

    工作中需要用到UEditor编辑文本,在与springMVC进行整合时,出现了一些问题,结果导致,在进行图片上传时出现如下提示: 上网查询了很多相关资料,此处简要记录下,防止以后遇到类似问题. 一种方 ...

  2. (转)Dubbo与Zookeeper、SpringMVC整合和使用

    原文地址: https://my.oschina.net/zhengweishan/blog/693163 Dubbo与Zookeeper.SpringMVC整合和使用 osc码云托管地址:http: ...

  3. SSM整合(三):Spring4与Mybatis3与SpringMVC整合

    源码下载 SSMDemo 上一节整合了Mybatis3与Spring4,接下来整合SpringMVC! 说明:整合SpringMVC必须是在web项目中,所以前期,新建的就是web项目! 本节全部采用 ...

  4. Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)

    互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,Dubbo是一个分布式服务框架,在这种情况下诞生的.现在核心业务抽取出来,作为独立的服务,使 ...

  5. springmvc整合fastjson

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  6. 【转】Dubbo_与Zookeeper、SpringMVC整合和使用(负载均衡、容错)

    原文链接:http://blog.csdn.net/congcong68/article/details/41113239 互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服 ...

  7. 160906、Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)

    互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,Dubbo是一个分布式服务框架,在这种情况下诞生的.现在核心业务抽取出来,作为独立的服务,使 ...

  8. Springmvc整合tiles框架简单入门示例(maven)

    Springmvc整合tiles框架简单入门示例(maven) 本教程基于Springmvc,spring mvc和maven怎么弄就不具体说了,这边就只简单说tiles框架的整合. 先贴上源码(免积 ...

  9. SpringMVC整合Tiles框架

    SpringMVC整合Tiles框架 Tiles组件 tiles-iconfig.xml Tiles是一个JSP布局框架. Tiles框架为创建Web页面提供了一种模板机制,它能将网页的布局和内容分离 ...

随机推荐

  1. tflearn mnist 使用MLP 全连接网络一般都会加dropout哇

    # -*- coding: utf-8 -*- """ Deep Neural Network for MNIST dataset classification task ...

  2. Flink之DataStreamAPI入门

    目录 Types Transformations Defining UDFs 本文API基于Flink 1.4 def main(args: Array[String]) { // 第一种会自动判断用 ...

  3. 基于Angular4+ server render(服务端渲染)开发教程

    目标: 1.更好的 SEO,方便搜索爬虫抓取页面内容 2.更快的内容到达时间(time-to-content) 影响: 1.用户:比原来更快的看到渲染的页面,提升用户体验 2.开发人员:某些代码可能需 ...

  4. android service--delphixe 10.3

    开发中的陷阱: 1. 别放什么 *.wav文件,这个 服务窗口不能随便放东西,不然铁定出现意想不到的结果,比如 无法运行,因为没 ui界面,随意都不知是啥问题. 2. 不能加载 datamodule ...

  5. Mysql数据库系列

    详情点击 MySQL基础 Mysql表操作 Mysql插入 更新 删除 查询操作 Mysql创建用户和授权 基本的Mysql语句 Mysql库的操作 Mysql表的操作 Mysql数据类型(一) My ...

  6. BZOJ 2101 DP+优化

    思路: http://www.cnblogs.com/exponent/archive/2011/08/14/2137849.html f[i,i+len]=sum[i,i+len]-min(f[i+ ...

  7. 关于SSL证书配置、升级的一些问题总结

    SSL会成为网站.APP.小程序(小程序已经强制使用https)等项目的标配.关于SSL证书安装使用的问题今天总结下,以备用. 环境配置:windows server 2008 R2和IIS7.0 1 ...

  8. 【JAVA练习】- 接收三个班各四个学员的成绩,算平均分

    package class_average; import java.util.Scanner;//调用Scanner类 public class average { public static vo ...

  9. SQL Server存储过程作业(三)

    阶段4:练习——插入入住客人记录 需求说明 使用存储过程将入住客人信息插入客人信息表中,要求: 检查身份证号必须是18个字符组成 押金的默认值为1000元 如果客人记录插入成功,输出客人流水号:否则输 ...

  10. linux route命令的使用详解(转)

    route命令用于显示和操作IP路由表.要实现两个不同的子网之间的通信,需要一台连接两个网络的路由器,或者同时位于两个网络的网关来实现.在Linux系统中,设置路由通常是 为了解决以下问题:该Linu ...