我试图了解整个
Spring框架.据我所知,使用gradle的相对较新的技术使很多教程和帖子在线过时了?
我运行的主要问题是当我尝试显示jsp或html页面时,网页的正文显示文本:“filename.jsp”.
该项目由New->创建.其它 – >使用Gradle和STS 3.7的Spring Starter项目.
目标是使用MVC模式创建Web应用程序.
文件夹结构:
测试
– 春天元素(由STS创建)
–src /主/ JAVA
– 测试
–TestApplication.java(由STS创建)
–TEST.Controller
–JSPController.java
–sec /主/资源
–application.properties(由STS创建,EMPTY文件)
–src / main / webapp(**我创建了这个目录,但是这是必需的吗?)
–Web-INF
–home.jsp
–home.html
–web.xml(**下面的附加问题)
TestApplication.java
package TEST;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
针对home.jsp
pageEncoding="ISO-8859-1"%>
TestTest 1
First name:
Last name:
JSPController.java
package TEST.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class JSPController {
@RequestMapping(value = "/jsp", method = RequestMethod.GET)
public String home(){
return "/webapp/WEB-INF/home.jsp";
}
}
web.xml中
//empty file right now
的build.gradle
buildscript {
ext {
springBootVersion = '1.2.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.spring.gradle:dependency-management-plugin:0.5.1.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
jar {
baseName = 'TEST'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
当我去http://localhost:8080/jsp,
html页面有正文:/webapp/WEB-INF/home.jsp
所以jsp根本没有显示.我已经尝试过html,有或没有方法= RequestMethod.GET / POST.什么都行不通.
**其他问题:
许多在线帖子/教程都会使用.xml文件,例如web.xml.根据我的理解,不再需要或不需要这些,因为spring gradle会自动从@notations生成.xml?