码迷,mamicode.com
首页 > 其他好文 > 详细

Ueditor编辑器与struts2结合使用

时间:2014-12-15 18:43:52      阅读:436      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   os   使用   sp   

1.新建一个filter

 1 package cn.lddxfs.tieba.filter;
 2 
 3 import java.io.IOException;
 4 
 5 import javax.servlet.FilterChain;
 6 import javax.servlet.ServletException;
 7 import javax.servlet.ServletRequest;
 8 import javax.servlet.ServletResponse;
 9 import javax.servlet.http.HttpServletRequest;
10 
11 import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;
12 
13 public class MyStruts2Filter extends StrutsPrepareAndExecuteFilter {
14 
15     public void doFilter(ServletRequest req, ServletResponse res,
16             FilterChain chain) throws IOException, ServletException {
17         HttpServletRequest request = (HttpServletRequest) req;
18         // 不过滤的url
19         String url = request.getRequestURI();
20         
21         if (url.endsWith("/ueditor/jsp/controller.jsp")) {
22             System.out.println("自定义"+url);
23             chain.doFilter(req, res);
24         }
25         else if (url.contains("/ueditor/jsp/upload/")) {
26             System.out.println("自定义"+url);
27             chain.doFilter(req, res);
28         }
29         else {
30             System.out.println("默认"+url);
31             super.doFilter(req, res, chain);
32         }
33     }
34 
35 }

将以下ueditor自带的jar包复制到WEB-INF/lib/   文件夹下

bubuko.com,布布扣

WEB-INF/lib/ueditor-1.1.1.jar删除,将ueditor/jsp/src下的文件复制到项目src文件夹。

修改

package com.baidu.ueditor.hunter下类FileManager中的getPath方法:

 1     private String getPath(File file) {
 2 
 3         String path = PathFormat.format(file.getAbsolutePath());
 4         String myrootString = this.rootPath.substring(0, this.rootPath
 5                 .substring(0, this.rootPath.length() - 1).lastIndexOf("/")+1);
 6 
 7         String myPath = path.replace(myrootString, "/");
 8         //System.out.println(myPath);
 9         return myPath;
10     }

 


2.在web.xml下添加以下内容

 1     <filter>
 2         <display-name>MyStruts2Filter</display-name>
 3         <filter-name>MyStruts2Filter</filter-name>
 4         <filter-class>cn.lddxfs.tieba.filter.MyStruts2Filter</filter-class>
 5     </filter>
 6     <filter-mapping>
 7         <filter-name>MyStruts2Filter</filter-name>
 8         <url-pattern>/*</url-pattern>
 9         <dispatcher>REQUEST</dispatcher>
10         <dispatcher>FORWARD</dispatcher>
11     </filter-mapping>

同时删除struts2的默认过滤器的配置

3.将ueditor解压后放到如下图位置,注意ueditor文件夹与WEB-INF同级。

bubuko.com,布布扣

4.找到ueditor/jsp/config.json文件修改文件内容,如图中标注。加一个点,文件中的/ueditor/jsp/upload 都替换为   ./ueditor/jsp/upload

bubuko.com,布布扣

5.将文件ueditor/index.html内容  复制到WEB-INF/index.jsp中

修改导入js的路径,如下

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <%@taglib uri="/struts-tags" prefix="s"%>
 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 5 <html>
 6 <head>
 7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 8 <title>测试ueditor</title>
 9 <link href="${pageContext.request.contextPath}/ba/css/list.css"
10     rel="stylesheet">
11 </head>
12 <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/ueditor/ueditor.config.js"></script>
13 <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/ueditor/ueditor.all.min.js">
14 </script>
15 <body>
16 。。。


6浏览器输入http://localhost:8080/项目名称/index.jsp 即可,最终效果如下图

bubuko.com,布布扣

 

Ueditor编辑器与struts2结合使用

标签:style   blog   http   io   ar   color   os   使用   sp   

原文地址:http://www.cnblogs.com/LDDXFS/p/4165270.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!