springboot把jsp页面放在resources下,为什么访问不到
1个回答
展开全部
举例说明:
Project Structure
└─main
├─java
│ └─com
│ └─henry
│ └─jsp
│ SampleWebJspController.java
│
└─resources
│ application.properties
│
└─META-INF
└─resources
└─WEB-INF
└─jsp
welcome.jsp
pom file
<拆兆dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>8.0.28</version>
</dependency>
java code
@Controller
@EnableAutoConfiguration
public class SampleWebJspController extends SpringBootServletInitializer {
@Value("${application.message:Hello World}")
private String message = "Hello World";
@RequestMapping("/")
public String welcome(Map<String, Object> model) {
model.put("time", new Date());
model.put("message", this.message);
return "welcome";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleWebJspController.class, args);
}
}
welcome.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
${message}
<div>${time}</div>
</body>
</html>
Start the project with main method and access localhost:8080 you can see the page.
Notice
At first I make a directory in src/main like webapp/WEB-INF/jsp and put all jsp in it. When I try to access root path with main method I got 404 page. I found there is no jsp file in jar. I changed the pom file like following
<packaging>war</packaging>
<dependencies>
<!-- dependency here -->
</dependencies>
<build>
<plugins>旅激租
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>铅颤${spring.boot.version}</version>
</plugin>
</plugins>
</build>
Project Structure
└─main
├─java
│ └─com
│ └─henry
│ └─jsp
│ SampleWebJspController.java
│
└─resources
│ application.properties
│
└─META-INF
└─resources
└─WEB-INF
└─jsp
welcome.jsp
pom file
<拆兆dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>8.0.28</version>
</dependency>
java code
@Controller
@EnableAutoConfiguration
public class SampleWebJspController extends SpringBootServletInitializer {
@Value("${application.message:Hello World}")
private String message = "Hello World";
@RequestMapping("/")
public String welcome(Map<String, Object> model) {
model.put("time", new Date());
model.put("message", this.message);
return "welcome";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleWebJspController.class, args);
}
}
welcome.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
${message}
<div>${time}</div>
</body>
</html>
Start the project with main method and access localhost:8080 you can see the page.
Notice
At first I make a directory in src/main like webapp/WEB-INF/jsp and put all jsp in it. When I try to access root path with main method I got 404 page. I found there is no jsp file in jar. I changed the pom file like following
<packaging>war</packaging>
<dependencies>
<!-- dependency here -->
</dependencies>
<build>
<plugins>旅激租
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>铅颤${spring.boot.version}</version>
</plugin>
</plugins>
</build>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询