M HYPE SPLASH
// updates

How to get access to the WEB-INF/views/some.jsp? spring mvc

By Sarah Scott

I successfully deployed my webapp to the Tomcat localhost. My app has 2 pages: localhost:8080/spring-mvc and localhost:8080/home. The first page has a link to the second. When I start my app, it successfully opens the first page, but when I follow the link to the second page the error appears:

HTTP Status 404 – Not Found.

It seems like there is no access to the WEB-INF/view folder. Can you help me to resolve this problem?

Project structure

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="" xmlns:xsi="" xsi:schemaLocation=" " version="4.0"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
</web-app>

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="" xmlns:xsi="" xsi:schemaLocation=" ">
</beans>

dispatcher-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="" xmlns:context="" xmlns:xsi="" xmlns:mvc="" xsi:schemaLocation=" "> <context:component-scan base-package="com.stoliarenko"/> <mvc:annotation-driven/> <bean> <property name="prefix" value="/WEB-INF/views/"/> <property name="suffix" value=".jsp"/> </bean>
</beans>

index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html> <head> <title>Index Page</title> </head> <body> <a href="/home">Go To Home Page!!</a> </body>
</html>

home.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head> <title>${pageTitle}</title>
</head>
<body>
${message}
</body>
</html>

HomeController.java

package com.stoliarenko;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HomeController { @RequestMapping(value = "/home") public ModelAndView home(){ ModelAndView modelAndView = new ModelAndView("home"); modelAndView.addObject("pageTitle", "Home Page"); modelAndView.addObject("message", "Hi, Welcome! This is HomePage!"); return modelAndView; }
}

1 Answer

Root Cause The class require to resolve the JSP path is available in tomcat jasper package and the dependency is not added in pom.xml. Hence, spring boot application is not able to resolve the jsp path.

Solution The dependent classes are available in tomcat jasper.

this link may be useful

0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy