I am trying to display a simple JSP on SpringBoot, but the screen is not displayed.
A 404 error was displayed and I am doing various things, but it has not changed at all.
Could someone give me some advice?
[Procedure]
1. New for STS Starter Project
2. Add the following to pom.xml
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
2. Add the following to application.properties
spring.mvc.view.prefix:/WEB-INF/views/
spring.mvc.view.suffix: .jsp
3. Create a folder directly under the project folder
src\main\webapp\WEB-INF\views
4. Place login.jsp in the views folder above.
Login.jsp Contents
<%@pagelanguage="java" contentType="text/html;charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello, World! JPS</title>
</head>
<body>
<p>Hello, World! JSP</p>
</body>
</html>
5.Create Controller Class
@Controller
public class LoginAction {
@RequestMapping(value="/", method=RequestMethod.GET)
public String index() {
return "login";
}
6. Run on STS to access the following URL in your browser.
http://localhost:8081/
7. Browser displays 404 errors and does not display JSP.
**Whitelabel Error Page**
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Jan 21 21:15:23 GMT + 09:00 2021
There was an unexpected error (type=Not Found, status=404).
Verified that RequestMapping is calling the method when viewed in debug mode.
I've tried many things, but I'm still in trouble.
What's missing?
If the questionnaire is correct,
spring.mvc.view.prefix:/WEB-INF/views/
There is a space at the end of the and you must also delete it.
Executable Code Sample (Differential)
© 2024 OneMinuteCode. All rights reserved.