Spring Boot JSP 404 [英] Spring Boot JSP 404
问题描述
我正在尝试在Spring Boot服务中添加一个jsp页面。我的问题是每次我尝试去那个页面时我都有:
I'm trying to add a jsp page in my Spring Boot service. My problem is that every time I try to go to that page I have this:
Whitelabel错误页面
Whitelabel Error Page
此应用程序没有/ error的显式映射,因此您将看到
这是一个后备。
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Apr 21 23: 16:00 EEST 2015出现意外错误(type = Not
Found,status = 404)。没有可用消息
Tue Apr 21 23:16:00 EEST 2015 There was an unexpected error (type=Not Found, status=404). No message available
我已将前缀和sufix添加到我的application.properties中:
I have added the prefix and sufix into my application.properties:
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
这是我的控制器类:
@Controller
public class MarkerController {
@RequestMapping(value="/map")
public String trafficSpy() {
return "index";
}
}
我的申请类:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
private static Logger logger = Logger.getLogger(Application.class.getName());
public static void main(String[] args) {
logger.info("SPRING VERSION: " + SpringVersion.getVersion());
SpringApplication.run(Application.class, args);
}
}
并且index.jsp:
And the index.jsp:
<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html lang="en">
<body>
<h1>Hello, World!!!</h1>
<p>JSTL URL: ${url}</p>
</body>
</html>
这是src文件结构:
├── src
│ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── internetprogramming
│ │ │ └── myserver
│ │ │ └── server
│ │ │ ├── Application.java
│ │ │ ├── config
│ │ │ │ └── DatabaseConfig.java
│ │ │ ├── controller
│ │ │ │ └── MarkerController.java
│ │ │ ├── dao
│ │ │ │ ├── MarkerDaoImplementation.java
│ │ │ │ └── MarkerDaoInterface.java
│ │ │ ├── Marker.java
│ │ │ └── service
│ │ │ ├── MarkerServiceImplementation.java
│ │ │ └── MarkerServiceInterface.java
│ │ ├── resources
│ │ │ └── application.properties
│ │ └── webapp
│ │ └── WEB-INF
│ │ └── jsp
│ │ └── index.jsp
推荐答案
确保依赖项列表中包含jasper和jstl:
Ensure that you have jasper and jstl in the list of dependencies:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
这是一个有效的启动项目 - https://github.com/spring-projects/spring-boot/tree / master / spring-boot-samples / spring-boot-sample-web-jsp
Here is a working starter project - https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-web-jsp
这篇关于Spring Boot JSP 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!