Spring Boot JSP 404
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>
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 basic JSP 404 Not Found
I needed to add this to my application.properties file:
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
Spring boot: 404 error when calling JSP using controller
Looks like you was very close to the working application. The main issue in your code is in <scope>provided</scope>
for your Jasper dependency.
And also looks like you are running your code from eclipse IDE through the main
method.
Long story short:
If you would like to run your application through the main
method in MyApplication.java
then just remove scope provided
for the Jasper.
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
Or you can run your application exactly in that state like you have right now from the console:
mvn clean spring-boot:run
But I suggest to remove this scope so you could be able to run your code from IDE and from console. In addition to that looks like spring-boot-starter-tomcat
dependency is redundant (it must be available within spring-boot-starter-web
). In a nutshell please try to use following pom file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/>
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
</dependencies>
</project>
Hope my answer will help you.
Spring Boot jsp file not found Error 404 weird prefix
Try to change the following property to start with a /
spring.mvc.view.prefix= /WEB-INF/jsp/
This will allow spring to search into subfolders of your webapp/WEB-INF/jsp
path.
Related Topics
How to Calculate the Number of Days in a Period
How to Declare a 2D String Arraylist
How to Convert a Hexadecimal String to Long in Java
In Java, When I Call Outputstream.Close() Do I Always Need to Call Outputstream.Flush() Before
Print Full Call Stack on Printstacktrace()
Why Were Most Java.Util.Date Methods Deprecated
Java: What's the Difference Between Autoboxing and Casting
How to Deserialize a Blank JSON String Value to Null for Java.Lang.String
Passing Parameters to a Jdbc Preparedstatement
What Is an "Internal Address" in Java
Using a Prepared Statement and Variable Bind Order by in Java with Jdbc Driver
Converting Date-String to a Different Format
How Does Java Garbage Collector Handle Self-Reference
Why Does Java App Crash in Gdb But Runs Normally in Real Life