gpt4 book ai didi

spring - 这个Spring Boot项目+ jsp的Gradle

转载 作者:行者123 更新时间:2023-12-03 03:46:36 24 4
gpt4 key购买 nike

我在这个Spring启动项目中使用Gradle,我的任务是创建另一个jsp文件,例如:index.jsp,并做一些Spring Boot可以生成该index.jsp的操作

我的问题是当我在webapp-> WEB_INF-> index.jsp中创建index.jsp时
它仅返回消息“索引”,而不是文件索引中的内容。

应用程序

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>

最佳答案

为JSP添加依赖项

compile('javax.servlet:jstl')
compile("org.apache.tomcat.embed:tomcat-embed-jasper")

而index.jsp PATH是 webapp / WEB_INF / jsp / index.jsp

如果需要示例 https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-web-jsp

关于spring - 这个Spring Boot项目+ jsp的Gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55016359/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com