解决ueditor编辑器图片在线管理图片无法显示

时间:2023-11-24 16:28:20

使用ueditor,点击在线管理,服务器图片路径显示不正确,如下图所示

解决ueditor编辑器图片在线管理图片无法显示
 查看源码,如下:

解决ueditor编辑器图片在线管理图片无法显示
 发现图片src中中间多了一长串的项目跟路径,解决的办法是

把  jsp/controller.jsp 里面的代码修改一下

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. import="com.baidu.ueditor.ActionEnter"
  3. pageEncoding="UTF-8"%>
  4. <%@ page trimDirectiveWhitespaces="true" %>
  5. <%
  6. request.setCharacterEncoding( "utf-8" );
  7. response.setHeader("Content-Type" , "text/html");
  8. String rootPath = application.getRealPath( "/" );
  9. String action = request.getParameter("action");
  10. String result = new ActionEnter( request, rootPath ).exec();
  11. if( action!=null &&
  12. (action.equals("listfile") || action.equals("listimage") ) ){
  13. rootPath = rootPath.replace("\\", "/");
  14. result = result.replaceAll(rootPath, "/");
  15. }
  16. out.write( result );
  17. %>

然后改config.json

  1. /* 列出指定目录下的图片 */
  2. "imageManagerActionName": "listimage", /* 执行图片管理的action名称 */
  3. "imageManagerListPath": "/ueditor/jsp/upload/image/", /* 指定要列出图片的目录 */
  4. "imageManagerListSize": 20, /* 每次列出文件数量 */
  5. "imageManagerUrlPrefix": "/ueditor", /* 图片访问路径前缀 */
  6. "imageManagerInsertAlign": "none", /* 插入的图片浮动方式 */
  7. "imageManagerAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 列出的文件类型 */