前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >旅游自助系统项目之百度富文本编辑器使用

旅游自助系统项目之百度富文本编辑器使用

作者头像
SmileNicky
发布2022-05-07 15:35:50
2620
发布2022-05-07 15:35:50
举报
文章被收录于专栏:Nicky's blog

Ueditor富文本编辑器是在很多项目里经常用到的框架,是百度开发团队开发的一款很好用的富文本编辑器

下面就是我在一个系统里用到的,有了富文本编辑器,管理员使用起来不是很方便?

所以本博客介绍这个富文本编辑器的使用哈!觉得写得不错的请点赞哈,有建议欢迎提哈!^V^

下载链接:http://ueditor.baidu.com/website/download.html

具体的使用请看官网:http://ueditor.baidu.com/website/index.html

下载富文本编辑器后,我们打开MyEclipse或者其它编辑软件,选择file->import,选择文件系统,导入下载好的Ueditor

然后启动tomcat服务器

http://localhost:8080/项目名称t/ueditor1_4_3_2/jsp/controller.jsp?action=config

这个要根据你的项目进行修改的哈

可以输出这个,什么编辑器导入成功

引入js,charset属性设置为UTF-8的,因为我的系统默认是UTF-8的

代码语言:javascript
复制
<span style="font-size:18px;"><script type="text/javascript" charset="UTF-8" src="<%=basePath %>ueditor1_4_3_2/ueditor.config.js"></script>
    <script type="text/javascript" charset="UTF-8" src="<%=basePath %>ueditor1_4_3_2/ueditor.all.min.js"> </script></span>

复制ueditor里面的index,html代码,这个要根据需要去复制的

代码语言:javascript
复制
<span style="font-size:18px;"><script type="text/javascript">

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例,如果在某个闭包下引用该编辑器,直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');


  
    function getContent() {
        var arr = [];
        arr.push("使用editor.getContent()方法可以获得编辑器的内容");
        arr.push("内容为:");
        arr.push(UE.getEditor('editor').getContent());
        alert(arr.join("\n"));
    }
    
   
</script></span>

因为我做的系统只要实现将编辑的文本和样式一起写入数据库,所以只要使用getContext方法就可以

在form表单里加入:

代码语言:javascript
复制
<script id="editor" type="text/plain" style="width:1024px;height:500px;"></script>

注意这些属性都不用随便修改的哦

获取文本和文本样式的参考代码,

String introduction = new String(request.getParameter("editorValue").getBytes("iso-8859-1"),"UTF-8");   这个就是获取文本和文本样式的代码,然后下面的代码只是参考的,只要用String introduction = new String(request.getParameter("editorValue").getBytes("iso-8859-1"),"UTF-8");   这代码就可以获取内容

代码语言:javascript
复制
public class AddSpotInfoServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		request.setCharacterEncoding("UTF-8");

		String introduction = new String(request.getParameter("editorValue").getBytes("iso-8859-1"),"UTF-8");
		String picture = Constant.ImgPath.path;
		String position = new String(request.getParameter("position").getBytes("iso-8859-1"),"UTF-8");
		String priceString = new String(request.getParameter("price").getBytes("iso-8859-1"),"UTF-8");
		Double price = Double.parseDouble(priceString);
		String sortString = new String(request.getParameter("sort").getBytes("iso-8859-1"),"UTF-8");
		int spot_sort = Integer.parseInt(sortString);
//		String timeString = new String(request.getParameter("time").getBytes("iso-8859-1"),"UTF-8");
//		Date time = Date.valueOf(timeString);
		String tour_project = new String(request.getParameter("tour_project").getBytes("iso-8859-1"),"UTF-8");
		
		Spot spot = new Spot();
		spot.setIntroduction(introduction);
		spot.setPicture(picture);
		spot.setPosition(position);
		spot.setPrice(price);
		spot.setSpot_sort(spot_sort);
		spot.setTour_project(tour_project);
		
		SpotDAO spotDao = new SpotDAOImpl();
		boolean flag = spotDao.addInfo(spot);
		if(flag){
			response.sendRedirect(Constant.WEB_URL_SPOT_SERVLET);
		}
		
		out.flush();
		out.close();
	}

	/**
	 * 
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}

ok,可以将文本和样式一起写入数据库了,哈哈哈,^V^

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-04-10,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
数据库
云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档