Reputation: 2192
May be everything okay but i'm getting error. basically i'm add view resolver properties in application properties file, then run this project and open a browser, browser show this error Whitelabel Error Page 404 file not found. I don't understand help me and suggested how to resolve this problem , i'm newbie in Spring Boot.in this blow my project detail's .
Error
2018-04-07 12:11:51.661 DEBUG 3740 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Returning [org.springframework.web.servlet.view.InternalResourceView: name 'home'; URL [/WEB-INF/jsp/home.jsp]] based on requested media type 'text/html'
2018-04-07 12:11:51.661 DEBUG 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Rendering view [org.springframework.web.servlet.view.InternalResourceView: name 'home'; URL [/WEB-INF/jsp/home.jsp]] in DispatcherServlet with name 'dispatcherServlet'
2018-04-07 12:11:51.661 TRACE 3740 --- [nio-8080-exec-1] o.s.w.servlet.view.InternalResourceView : Rendering view with name 'home' with model {} and static attributes {}
2018-04-07 12:11:51.684 DEBUG 3740 --- [nio-8080-exec-1] o.s.w.servlet.view.InternalResourceView : Forwarding to resource [/WEB-INF/jsp/home.jsp] in InternalResourceView 'home'
2018-04-07 12:11:51.687 TRACE 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Bound request context to thread: org.apache.catalina.core.ApplicationHttpRequest@3087f725
2018-04-07 12:11:51.687 DEBUG 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/WEB-INF/jsp/home.jsp]
2018-04-07 12:11:51.687 TRACE 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@7ba6a25a] in DispatcherServlet with name 'dispatcherServlet'
2018-04-07 12:11:51.687 TRACE 3740 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping : No handler mapping found for [/WEB-INF/jsp/home.jsp]
2018-04-07 12:11:51.687 TRACE 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Testing handler map [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@6d6680cb] in DispatcherServlet with name 'dispatcherServlet'
2018-04-07 12:11:51.687 DEBUG 3740 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /WEB-INF/jsp/home.jsp
2018-04-07 12:11:51.690 DEBUG 3740 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/WEB-INF/jsp/home.jsp]
2018-04-07 12:11:51.690 TRACE 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Testing handler map [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@1a14f49d] in DispatcherServlet with name 'dispatcherServlet'
2018-04-07 12:11:51.690 TRACE 3740 --- [nio-8080-exec-1] o.s.w.s.h.BeanNameUrlHandlerMapping : No handler mapping found for [/WEB-INF/jsp/home.jsp]
2018-04-07 12:11:51.690 TRACE 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@7b19df79] in DispatcherServlet with name 'dispatcherServlet'
2018-04-07 12:11:51.690 DEBUG 3740 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Matching patterns for request [/WEB-INF/jsp/home.jsp] are [/**]
2018-04-07 12:11:51.691 DEBUG 3740 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping : URI Template variables for request [/WEB-INF/jsp/home.jsp] are {}
2018-04-07 12:11:51.692 DEBUG 3740 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapping [/WEB-INF/jsp/home.jsp] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/], ServletContext resource [/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@73797478]]] and 1 interceptor
2018-04-07 12:11:51.692 TRACE 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Testing handler adapter [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter@44abba94]
2018-04-07 12:11:51.692 TRACE 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Testing handler adapter [org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter@f0e0b58]
2018-04-07 12:11:51.693 DEBUG 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Last-Modified value for [/WEB-INF/jsp/home.jsp] is: -1
2018-04-07 12:11:51.693 TRACE 3740 --- [nio-8080-exec-1] o.s.w.s.r.ResourceHttpRequestHandler : Path contains "WEB-INF" or "META-INF".
2018-04-07 12:11:51.693 TRACE 3740 --- [nio-8080-exec-1] o.s.w.s.r.ResourceHttpRequestHandler : Ignoring invalid resource path [WEB-INF/jsp/home.jsp]
2018-04-07 12:11:51.693 TRACE 3740 --- [nio-8080-exec-1] o.s.w.s.r.ResourceHttpRequestHandler : No matching resource found - returning 404
2018-04-07 12:11:51.693 DEBUG 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2018-04-07 12:11:51.693 TRACE 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Cleared thread-bound request context: org.apache.catalina.core.ApplicationHttpRequest@3087f725
build.gradle
buildscript {
ext {
springBootVersion = '2.0.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
group = 'com.ethxpay.book.ticket.app'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
configurations {
providedRuntime
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.apache.tomcat.emded:tomcat-embed-japer')
runtime('org.springframework.boot:spring-boot-devtools')
runtime('mysql:mysql-connector-java')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile group: 'javax.servlet', name: 'servlet-api', version: '3.0'
compile group: 'javax.servlet.jsp', name: 'jsp-api', version: '2.1'
}
application.properties
#Database Properties
spring.datasource.url=jdbc:mysql://localhost:3306/customerdb?useSSL=false
spring.datasource.username=root
spring.datasource.password=root
#View Resolver
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
#JPA/Hibernate properties
spring.jpa.show-sql=true
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
#Log
logging.level.org.hibernate.SQL:debug
logging.level.org.springframework: TRACE
logging.level.com: TRACE
Controller Class
@RestController
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@RequestMapping("/")
public ModelAndView index() {
return new ModelAndView("home");
}
@PostMapping("/createEmp")
public void createEmp(HttpServletRequest request, HttpServletResponse response) {
Employee emp = new Employee(request.getParameter("name"), request.getParameter("tel"),
request.getParameter("address"), Double.parseDouble(request.getParameter("sal")));
employeeService.create(emp);
}
}
Project-Seed
Upvotes: 2
Views: 17135
Reputation: 1
compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper', version: '9.0.7'
The above dependency worked for me.
Upvotes: 0
Reputation: 1262
RequestMappingHandlerMapping : Did not find handler method for [/WEB-INF/jsp/home.jsp]
Spring-boot application for getting jsp pages
Changes required in application.properties
spring.thymeleaf.mode=HTML5
spring.thymeleaf.enabled=false
spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp
Changes in pom.xml for themleaf related changes :
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
Upvotes: -1
Reputation: 21
The embedded tomcat needs the jasper dependency to render the jsp views in Spring boot application.
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
And if you require to write iteration, control statements in your jsp pages then also include JSTL i.e JSP Standard Tag Library in your pom.xml as follows:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
Upvotes: 2
Reputation: 3250
While using Maven and I was missing these dependencies -
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<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>
I have little to no knowledge on Gradle you can try to remove javax-servlet and jsp dependencies. As you already have tomcat and web dependencies added. Also if you are using, jstl, you can use this dependency -
compile('javax.servlet:jstl')
Upvotes: 11