Ueditor是百度开发的所见即所得富页面编辑器。感觉要比其他的第三方编辑器更有亲和性和更强操作性。
下面是我遇到并解决的问题:
1.加载顺序
<script type="text/javascript">
var editor = new baidu.editor.ui.Editor();
editor.render('myEditor');
</script>
这段代码必须放在<textarea id="myEditor"></textarea>的后面。注意不能放在<head>标签里面。
2.图片上传问题
1)、servlet+jsp环境
步骤:
A、修改ueditor/dialogs/image/image.html,找到url
改成'../../server/upload/jsp/imageUp.jsp', 注意路径
B、修改ueditor/editor_config,找到URL改成'/yourWebName/ueditor/',
imagePath改成"/yourWebName/"
2)、采用struts框架
拦截器把(/*)所有请求的文件都做了处理,所以导致无法上传图片。
解决方法,自定义拦截器,让它在请求imageUp.jsp文件时不做处理。
步骤:
A、创建拦截器类
- import java.io.IOException;
- import javax.servlet.FilterChain;
- import javax.servlet.ServletException;
- import javax.servlet.ServletRequest;
- import javax.servlet.ServletResponse;
- import javax.servlet.http.HttpServletRequest;
- import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;
- public class MyStrutsFilter extends StrutsPrepareAndExecuteFilter {
- public void doFilter(ServletRequest req, ServletResponse res,FilterChain chain) throws IOException, ServletException {
- HttpServletRequest request = (HttpServletRequest) req;
- //不过滤的url
- String url = request.getRequestURI();
- System.out.println(url);
- if ("/yourWebName/ueditor/server/upload/jsp/imageUp.jsp".equals(url)) {
- System.out.println("使用自定义的过滤器");
- chain.doFilter(req, res);
- }else{
- System.out.println("使用默认的过滤器");
- super.doFilter(req, res, chain);
- }
- }
- }
B、配置拦截器
把默认拦截器改为以下拦截器
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class>
- com.lijia.MyStrutsFilter
- </filter-class>
- </filter>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>