标签:
ueditor上传附件时显示和下载都是正常的,当下次点击在线附件时图片图标显示错误,再添加到网页中访问的时候出现404错误,比如:
第一次添加:http://192.168.1.4:8080/uedit2/ueditor/jsp/upload/file/20140622/1403423931425017681.png
第二次就变成了:http://192.168.1.4:8080/uedit2/C:/Program Files/Apache Software Foundation/Tomcat 7.0/wtpwebapps/uedit2/ueditor/jsp/upload/file/20140622/1403423931425017681.png
用firebug查看网络可以发现,当请求 controller.jsp?action=listimg 或者controller.jsp?action=listfile 的时候后端返回的url竟然是后台文件的绝对路径,导致前端无法访问资源时出现404错误。
虽然检查了配置文件很多次了,但是还是出现这个问题,也不知道是不是bug,ueditor后台代码挺复杂的,为了简单起见(怕改错) 就用了下面的方法偷懒一下。
把 jsp/controller.jsp 里面的代码修改一下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<%@ page language=
"java"
contentType=
"text/html; charset=UTF-8"
import
=
"com.baidu.ueditor.ActionEnter"
pageEncoding=
"UTF-8"
%>
<%@ page trimDirectiveWhitespaces=
"true"
%>
<%
request.setCharacterEncoding(
"utf-8"
);
response.setHeader(
"Content-Type"
,
"text/html"
);
String rootPath = application.getRealPath(
"/"
);
String action = request.getParameter(
"action"
);
String result =
new
ActionEnter( request, rootPath ).exec();
if
( action!=
null
&&
(action.equals(
"listfile"
) || action.equals(
"listimage"
) ) ){
rootPath = rootPath.replace(
"\\"
,
"/"
);
result = result.replaceAll(rootPath,
"/"
);
//把返回路径中的物理路径替换为 ‘/‘
}
out.write( result );
%>
|
标签:
原文地址:http://my.oschina.net/glenxu/blog/476849