当前位置: 代码迷 >> 综合 >> ueditor与ssh整合之上传图片篇
  详细解决方案

ueditor与ssh整合之上传图片篇

热度:46   发布时间:2024-01-20 22:43:18.0

1. 加入插件

<script type="text/javascript" src="scripts/ueditor/ueditor.config.js"></script>

<script type="text/javascript" src="scripts/ueditor/ueditor.all.min.js"></script>

2.创建容器

<script id="container" name="content" type="text/plain">
    </script>

3.实例化容器

var ue = UE.getEditor('container',{
initialFrameHeight:600, 
})

4.重写struts2的拦截器

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 {@Overridepublic void doFilter(ServletRequest req, ServletResponse res,FilterChain chain) throws IOException, ServletException {HttpServletRequest request = (HttpServletRequest) req;String url = request.getRequestURI();         System.out.println(url);         if (url.contains("/blog/scripts/ueditor/jsp/")) {             System.out.println("使用自定义过滤器");             chain.doFilter(req, res);         }else{             System.out.println("使用默认过滤器");             super.doFilter(req, res, chain);         } }
}

5.web.xml里

将

<filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping>
替换成自己写的拦截器

 <filter><filter-name>struts2</filter-name><filter-class>com.blog.until.MyStrutsFilter</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping>

5.修改ueditor/ueditor.config.js文件里

window.UEDITOR_HOME_URL = "/blog/scripts/ueditor/"

6.修改ueditor/jsp/config.json文件

"imageUrlPrefix": "/blog", /*图片前缀(项目名) */
"imagePathFormat": "/img/{yyyy}{mm}{dd}/{time}{rand:6}",(图片保存地址)