1、将utf8-jsp整个文件夹拷贝到idea的webapp文件夹下面,改名为ueditor
2、导入ueditor的pom文件的坐标
<dependency>
<groupId>com.baidu.ueditor</groupId>
<artifactId>ueditor</artifactId>
<version>1.1.2</version>
</dependency>
3、在webapp下新建index.jsp,内容如下
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>完整demo</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<script type="text/javascript" charset="utf-8" src="ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="ueditor/ueditor.all.min.js"></script>
<!--建议手动加在语言,避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型,比如你在配置项目里配置的是英文,这里加载的中文,那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="ueditor/lang/zh-cn/zh-cn.js"></script>
<style type="text/css">
div {
width: 100%;
}
</style>
</head>
<body>
<div>
<form action="ueditorServlet" enctype="multipart/form-data">
<h1>完整demo</h1>
<script id="editor" type="text/plain">
</script>
<input type="submit" value="提交"/>
</form>
</div>
<script type="text/javascript">
var ue = UE.getEditor('editor');
</script>
</body>
</html>
现在可以在浏览器中打开界面,说明基本配置已经搭建完成。
4、创建UeditorServlet
package cn.hello.editor;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class UeditorServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
resp.setCharacterEncoding("UTF-8");
String content = req.getParameter("editorValue");
if(content != null){
req.setAttribute("content",content);
req.getRequestDispatcher("content.jsp").forward(req, resp);
}else{
resp.getWriter().append("内容为空!");
}
}
}
在web.xml中配置ueditorServlet
<servlet>
<servlet-name>ServletDemo1</servlet-name>
<servlet-class>cn.hello.editor.UeditorServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletDemo1</servlet-name>
<url-pattern>/ueditorServlet</url-pattern>
</servlet-mapping>
content.jsp的代码如下
<%@ page language="java" import="java.util.*" 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">
<html>
<head>
<base href="<%=basePath%>">
<title>提交成功</title>
</head>
<body>
<%
out.print(request.getRealPath(""));
%>
<div> ${content } </div>
</body>
</html>
运行tomcat,文本内容已经可以正常传递。