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 html
用firebug查看网络能够发现,当请求 controller.jsp?action=listimg 或者controller.jsp?action=listfile 的时候后端返回的url居然是后台文件的绝对路径,致使前端没法访问资源时出现404错误。 前端
虽然检查了配置文件不少次了,可是仍是出现这个问题,也不知道是否是bug,ueditor后台代码挺复杂的,为了简单起见(怕改错) 就用了下面的方法偷懒一下。 java
把 jsp/controller.jsp 里面的代码修改一下 web
<%@ 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 ); %>