I recently switched one of my static html files to a Spring controller that uses JSP to render its presentation. I use the pier for testing locally, and local testing shows what the page rendering looks like. After deploying to our test server that uses Tomcat 6.0.26, I get the following exception:
javax.servlet.ServletException: Could not get RequestDispatcher for [/WEB-INF/jsp/index.jsp]: check that this file exists within your WAR org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:219) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549) javax.servlet.http.HttpServlet.service(HttpServlet.java:617) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
I confirmed that JSP exists in the war I am deploying and the exploded directory that tomcat creates when deployed. Here's what my web.xml and front-controller-servlet.xml files look like (web.xml is a bit short):
<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>gwtrpc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>gwtrpc</servlet-name> <url-pattern>*.gwtrpc</url-pattern> </servlet-mapping> <servlet> <servlet-name>front-controller</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>front-controller</servlet-name> <url-pattern>/search.html</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>front-controller</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
front controller-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:security="http://www.springframework.org/schema/security" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd"> <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/search.html">indexController</prop> </props> </property> </bean> <bean id="indexController" class="com.company.search.web.server.controller.IndexController" /> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp"/> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> </bean> </beans>
The difference between my Dev instance and the test instance is that the DEV instance is deployed to the root directory (local / search.html), while the test instance is deployed to server.com/appname/search.html. Appname is the name of the * .war file that I am deploying. I tried to add the full path as a prefix to the jps files (/ appname / WEB-INF / jsp /) and a number of other combinations with no luck. I confirmed that jsp-api jars are in the tomcat lib directory. My tomcat installation is a basic / standard installation.
source share