spring - 此 Spring Boot 项目的 Gradle + jsp

标签 spring spring-boot jsp gradle

我在这个 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

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

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

相关文章:

java - 内部 Servlet 映射 - web.xml

java - 如何将一个简单的 Spring Boot(带有 Gradle 构建系统)部署到 Apache Tomcat(真实服务器,而非嵌入服务器)?

spring - javax.servlet.ServletException : Circular view path [error]: would dispatch back to the current handler URL [/error] again - Spring Cloud

java - 无法使用 RestTemplate 解析 REST 响应

java - 当使用 Spring Integration 从队列中读取的消息在 Transacted 情况下为 ACK 时

java - 使用 Firebase 在 Android 应用程序中使用 Spring Boot

java - 某些父实体值无法保存到子实体

java - 无法从 Jsp 文件中的 servlet 接收响应

JAVASCRIPT 值到 JSP 变量

java - 损坏的 Spring Boot 调试过程 - 忽略断点