我在这个Spring启动项目中使用Gradle,我的任务是创建另一个jsp文件,例如:index.jsp,并做一些Spring Boot可以生成index.jsp的事情
我的问题是当我在webapp-> WEB_INF-> index.jsp中创建index.jsp时 它只会返回消息“索引”,而不是文件索引中的内容。
Application.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";
}
}
Application.properties
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
build.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>
答案 0 :(得分:0)
为JSP添加依赖项
compile('javax.servlet:jstl')
compile("org.apache.tomcat.embed:tomcat-embed-jasper")
和index.jsp路径为 webapp / WEB_INF / jsp / index.jsp 。
答案 1 :(得分:0)
您必须在班级@Controller
中使用@RestController
注释而不是PledgeController
。
@Controller
public class PledgeController {
@GetMapping("/hello")
public String getHelloMessage() {
return "index";
}
}