我在这个 Spring boot 项目中使用 Gradle,我的任务是创建另一个 jsp 文件,例如:index.jsp 并执行 Spring boot 可以生成该 index.jsp 的操作
我的问题是当我在 webapp -> WEB_INF -> index.jsp 中创建 index.jsp 时 它只返回消息“index”,而不是文件索引中的内容。
应用程序.java
package edu.msudenver.tsp.website;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
PledgeController.java
package edu.msudenver.tsp.website.controllers;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class PledgeController {
@GetMapping("/hello")
public String getHelloMessage() {
return "index";
}
}
应用程序属性
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
构建.gradle
buildscript {
ext {
springBootVersion = '1.5.6.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
index.jsp
> <%@ page contentType="text/html;charset=UTF-8" language="java" %>
> <html> <head>
> <title>Hello Spring mvc</title> </head> <body>
最佳答案
添加JSP依赖
compile('javax.servlet:jstl')
compile("org.apache.tomcat.embed:tomcat-embed-jasper")
和index.jsp路径是webapp/WEB_INF/jsp/index.jsp。
关于spring - 此 Spring Boot 项目的 Gradle + jsp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55016359/