您的位置:首页 > 编程语言 > Java开发

嵌入百度UEditor到JAVA+MAVEN+SpringMVC项目中

2016-10-26 19:42 489 查看
1、下载UEditor JSP版本

  http://ueditor.baidu.com/website/download.html
2、嵌入UEditor 到项目

1、解压刚刚下载的ueditor1_4_3_3-utf8-jsp.zip后;

2、然后把文件夹名称修改成ueditorutf8或者ueditor等容易辨识的文件夹名称;

3、把修改好名字的文件夹嵌入到JAVA项目的webapp;

4、把ueditorutf8/jsp/lib文件夹下的JAR 复制加入到WEB-INF文件夹下的lib文件夹;

5、选中刚刚拷贝好的jar文件,右键后Build Path--->add 到项目中;



3、配置spring-mvc.xml的权限与资源

1、设置静态资源

<mvc:resources mapping="/ueditorutf8/**" location="/ueditorutf8/**"
cache-period="31556926" />


2、跳过权限限制

如果没有有设置拦截器,不用执行这一步

如果有则添加下列代码中的“不需要拦截的地址”节点

<span style="white-space:pre">	</span><!-- Session失效拦截 -->
<mvc:interceptors>
<!-- 定义拦截器 -->
<mvc:interceptor>
<!-- 匹配的是url路径, 如果不配置或/**,将拦截所有的Controller -->
<mvc:mapping path="/**" />
<!-- 不需要拦截的地址 -->
<mvc:exclude-mapping path="/ueditorutf8/**" />
</mvc:interceptor>
</mvc:interceptors>


4、新增JSP页面

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 配置文件 -->
<script type="text/javascript" src="/ueditorutf8/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/ueditorutf8/ueditor.all.js"></script>
<!-- 语言包文件(建议手动加载语言包,避免在ie下,因为加载语言失败导致编辑器加载失败) -->
<script type="text/javascript" src="/ueditorutf8/lang/zh-cn/zh-cn.js"></script>
<title>Insert title here</title>
</head>
<body>
<script id="container" name="content" type="text/plain">这里写你的初始化内容</script>
<script type="text/javascript">
var editor = UE.getEditor('container', {
//默认的编辑区域高度
initialFrameHeight : 300,
//默认的编辑区域宽度
initialFrameWidth : 800
})
</script>
</body>
</html>


5、执行效果

程序的内容不属于本博客的内容,指定跳转到上一步新增的JSP页面

执行效果如下图:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐