首页 > 运营 > 软件工具 > 正文

关于jsp版ueditor1.2.5的部分问题解决(上传图片失败)

2020-10-06 22:54:23
字体:
来源:转载
供稿:网友

1. 关于上传图片失败的问题

首先导入jar包
commons-fileupload-1.2.2.jar,ueditor.jar

然后修改editor_config.js

找到并修改 URL 修改为  window.UEDITOR_HOME_URL||"/mypro/ueditor/"  其中mypro是我的项目名称

imagePath 修改为 URL + "upload/"
假设我们的图片存储路径是ueditor/upload/

然后修改 imageUp.jsp
up.setSavePath("") 修改为 up.setSavePath("../imageUp");
这样就设置图片的存储路径为ueditor/upload/imageUp

然后如果没有在web.xml中配置struts2的拦截器的话,应该可以上传成功了,然后如果需要结合struts2拦截器,则需要另外添加配置

原理是这样的,就是自己创建一个拦截器,替换默认的拦截器,然后将所不需要拦截的路径过滤,其余的还是用默认拦截器

首先创建一个拦截器类

复制代码 代码如下:

public class MyStrutsFilter extends StrutsPrepareAndExecuteFilter {
 public void doFilter(ServletRequest req, ServletResponse res,
   FilterChain chain) {
  HttpServletRequest request = (HttpServletRequest) req;
  String url = request.getRequestURI();
  if (url.contains("ueditor/jsp/")) {<SPAN style="WHITE-SPACE: pre">  </SPAN>//这里是将整个文件夹下的文件都过滤了
   try {
    chain.doFilter(req, res);
   } catch (IOException e) {
    e.printStackTrace();
   } catch (ServletException e) {
    e.printStackTrace();
   }
  } else {
   try {
    super.doFilter(req, res, chain);// 采用默认父类的拦截器,即 struts2
   } catch (IOException e) {
    e.printStackTrace();
   } catch (ServletException e) {
    e.printStackTrace();
   }
  }
 }
}

然后在web.xml中定义

复制代码 代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
 xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  <display-name></display-name> 
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
    <session-config>   
        <session-timeout>30</session-timeout>   
    </session-config> 
  <filter>
  <filter-name>struts2</filter-name>
  <filter-class> 
        cn.xyx.web.filter.MyStrutsFilter
        <!-- 这里使用自定义拦截器,.jsp不做处理,其他使用默认拦截器 -
         注意这里替换了默认的struts2的 拦截器 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter -->
    </filter-class>
  </filter>
  <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
  <error-page>
   <error-code>404</error-code>
   <location>/404.jsp</location>
 </error-page>
  </web-app>

这样配置就可以了

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表