關於jsp版ueditor1.2.5的部分問題解決(上傳圖片失敗)

來源:互聯網
上載者:User

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>

這樣配置就可以了

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.