java配置ueditor

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,文本内容已经可以正常传递。
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值