后端技术
JAVA SpringBoot2 整合 JSP视图模板 整合 Ueditor富文本编辑器
2020-11-23 64 0
简介 JAVA SpringBoot2 整合 JSP视图模板 整合 Ueditor富文本编辑器
JAVA SpringBoot2 整合 JSP视图模板 整合 Ueditor富文本编辑器

weixin_30417487 2018-10-18 11:13:00
87
收藏
4.0.0
com.hwq
jsp
0.0.1-SNAPSHOT
jar
jsp
整合 JSP 页面
org.springframework.boot
spring-boot-starter-parent
2.0.6.RELEASE
UTF-8
UTF-8
1.8
1.8
1.8
1.8
org.springframework.boot
spring-boot-starter-web
javax.servlet
javax.servlet-api
javax.servlet
jstl
org.apache.tomcat.embed
tomcat-embed-jasper
com.gitee.qdbp.thirdparty
ueditor
1.4.3.3
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin
1.4.2.RELEASE
src/main/webapp
META-INF/resources
**/**
src/main/resources
**/**
false
package com.hwq.jsp;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;/**
* 想要集成 JSP 页面,启动类需要继承 SpringBootServletInitializer
* 需要重写 configure 方法
* 测试阶段要把启动方式的工作环境调成当前模块,否则多模块下回找不到视图页面 */@SpringBootApplicationpublic class JspApplication extends SpringBootServletInitializer {
@Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(JspApplication.class);
} public static void main(String[] args) {
SpringApplication.run(JspApplication.class, args);
}
}package com.hwq.jsp.controller;import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import javax.servlet.http.HttpServletRequest;
@Controllerpublic class UeditorController {
@Value("${ueditor.path}") private String ueditorUrl;
@RequestMapping("/ueditor/jsp/controller") public String action(HttpServletRequest request) { // 将读取出来的文件保存地址保存到 request 中
request.setAttribute("path", ueditorUrl); return "ueditor/jsp/controller";
}
}<%@ 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"); // 获取在控制器中赋值的 ueditor 上传文件的外置存放地址
String rootPath = (String) request.getAttribute("path");
String action = request.getParameter("action");
String result = new ActionEnter(request, rootPath ).exec(); // 这里修复 ueditor 本身的 bug, (获取图片列表和文件列表的时候,会出现绝对路径的情况)
if (action != null && (action.equals("listfile") || action.equals("listimage"))) {
result = result.replaceAll(rootPath, "/");
}
out.write( result );%>










