百度富文本编辑jsp上传_百度富文本编辑器ueditor在jsp中的使用(ssm框架中的应用)...

本文详细记录了在SSM(Spring、SpringMVC、MyBatis)框架中集成百度富文本编辑器ueditor的过程,包括解决maven依赖、json注释、静态资源访问等问题,最终实现ueditor在jsp页面上的成功显示。
摘要由CSDN通过智能技术生成

折腾了一下午终于把百度富文本编辑器ueditor搞定了!

项目地址:https://github.com/724888/lightnote_new

首先我参考了一个ueditor的demo。

下载地址:http://download.csdn.net/download/lookthatgirl/5651763

demo的项目结构

导入工程后配置一下build path将jar配置好即可运行,当然可能存在error,解决即可。

但是要将这个编辑器加入到我自己的页面中时遇到了点麻烦。

首先 问题一:

maven配置;

其中一些jar包有maven仓库地址,而另外一些并没有。

io,json,upload这些可以直接搜到,不过ueditor就没有了,

这里贴上所有的dependency地址。

commons-fileupload

commons-fileupload

1.3.1

org.json

json

20140107

org.webjars.bower

ueditor

1.4.3

commons-io

commons-io

2.2

commons-codec

commons-codec

1.9

其中ueditor是mavenrepository里提供的地址。

如果不愿意配置pom.xml,也可以直接把jar包加入到build path,一样可以运行。

其次 问题二:

官方提供的工程存在bug,主要有几个问题,

1是json文件中有注释,可用正则表达式的替换来删除注释

2是show.html文件中的error,原因是&符号不能被识别,需要改成&即可解决。

3是jar包缺失导致的一些import错误,将jar包配置好应该可以解决。

问题三:

jsp文件中已配置好文字编辑器,但是无法成功显示。几经测试,与jar包无关。

后终于找到其原因,资源文件没有读取到。

这是我的工程结构

ueditor.jsp:

Stringapath=request.getContextPath();StringabasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+apath+"/";

out.print(abasePath+"dassa");%>

My JSP ‘index.jsp‘ starting page

ueditor/ueditor.config.js">

ueditor/ueditor.all.js">

vareditor= newUE.ui.Editor();

editor.render("myEditor");//1.2.4以后可以使用一下代码实例化编辑器

//UE.getEditor(‘myEditor‘)

仔细检查了几次,发现js目录也没有写错,但是就是显示不出编辑器。

而jsp中只包含了js文件,只可能是js出现问题,于是我开始寻找资源文件配置的问题。

由于我使用的是ssm框架,以下是我的相关配置文件:

web.xml:

1 <?xml version="1.0" encoding="UTF-8"?>

2

3 lightnote

4

5 encodingFilter

6 org.springframework.web.filter.CharacterEncodingFilter

7

8 encoding

9 UTF-8

10

11

12

13 encodingFilter

14 /*

15

16

17 org.springframework.web.context.ContextLoaderListener

18

19

20 org.springframework.web.util.IntrospectorCleanupListener

21

22

23 contextConfigLocation

24 classpath:/spring-mybatis/spring-mybatis.xml

25

26

27

//此处经过修改

54

55

56

57 springmvc

58 org.springframework.web.servlet.DispatcherServlet

59

60 contextConfigLocation

61 classpath:/springmvc-servlet/springmvc-servlet.xml

62

63 1

64

65

66 springmvc

67 /

68

69

70

71

72

73

74 log4jConfigLocation

75 classpath:/properties/log4j.properties

76

77

78 org.springframework.web.util.Log4jConfigListener

79

80

81 index.jsp

82 login.jsp

83 ueditor.jsp

84

85

86

87

88 webAppRoot

89 lightnote.root

90

91

所有资源都会被dispatcherserlvet拦截。

并且在spring配置文件中会对静态资源文件进行处理。

spring-servlet.xml:

1 <?xml version="1.0" encoding="UTF-8"?>

2

3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

4 xmlns:context="http://www.springframework.org/schema/context"

5 xmlns:mvc="http://www.springframework.org/schema/mvc"

6 xsi:schemaLocation="http://www.springframework.org/schema/beans7 http://www.springframework.org/schema/beans/spring-beans.xsd8 http://www.springframework.org/schema/context9 http://www.springframework.org/schema/context/spring-context.xsd10 http://www.springframework.org/schema/mvc11 http://www.springframework.org/schema/mvc/spring-mvc.xsd">

12

13

14

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

但是由于spring配置文件只对固定的三个资源文件夹进行扫描。无法扫描到其他的文件夹。

所以jsp页面才加载不到ueditor文件夹里的静态资源。

于是我做了以下修改:

1 <?xml version="1.0" encoding="UTF-8"?>

2

3 lightnote

4

5 encodingFilter

6 org.springframework.web.filter.CharacterEncodingFilter

7

8 encoding

9 UTF-8

10

11

12

13 encodingFilter

14 /*

15

16

17 org.springframework.web.context.ContextLoaderListener

18

19

20 org.springframework.web.util.IntrospectorCleanupListener

21

22

23 contextConfigLocation

24 classpath:/spring-mybatis/spring-mybatis.xml

25

26

27

28

29 default

30 *.css

31

32

33 default

34 *.gif

35

36

37 default

38 *.jpg

39

40

41 default

42 *.png

43

44

45 default

46 *.js

47

48

49

50

51 default

52 *.html

53

54

55

56

57 springmvc

58 org.springframework.web.servlet.DispatcherServlet

59

60 contextConfigLocation

61 classpath:/springmvc-servlet/springmvc-servlet.xml

62

63 1

64

65

66 springmvc

67 /

68

69

70

71

72

73

74 log4jConfigLocation

75 classpath:/properties/log4j.properties

76

77

78 org.springframework.web.util.Log4jConfigListener

79

80

81 index.jsp

82 login.jsp

83 ueditor.jsp

84

85

86

87

88 webAppRoot

89 lightnote.root

90

91

增加

28

29 default

30 *.css

31

32

33 default

34 *.gif

35

36

37 default

38 *.jpg

39

40

41 default

42 *.png

43

44

45 default

46 *.js

47

在dispatcherservlet截获请求之前会让defaultservlet对静态资源进行处理。

并把spring-servlet.xml中的静态资源配置代码删除。

这样即可以让jsp页面访问到其他文件夹的静态资源了。

于是百度富文本编辑器就可以使用了!

原文:http://www.cnblogs.com/xll1025/p/6383757.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值