Spring MVC 3 Web.xml welcome file (index.jsp) doesn't get displayed 404
The WEB-INF
folder is not accessible publicly. So you have to put your index.jsp
somewhere reachable, for instance in the web application root folder.
/mywebapp
/WEB-INF/
/index.jsp
Scribe74
Updated on June 05, 2022Comments
-
Scribe74 almost 2 years
Hope you can help because as far as I can see, this is set up correctly (but please prove me wrong).
I have my spring 3 mvc project configured as follows:
web.xml
<servlet> <servlet-name>myServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>myServlet</servlet-name> <url-pattern>/frontPage</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/myServlet-service.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
And myServlet-servlet.xml
<mvc:annotation-driven /> <context:component-scan base-package="my.path.to.controllers" /> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/" /> <property name="suffix" value=".jsp" /> </bean>
I have an index.jsp within WEB-INF (not WEB-INF/views) that does nothing more than say "Hello" (I was originally trying to get it to forward to /frontPage).
Now, if I type in the url for the controllers (localhost:8080/myServlet/frontPage), the controller works and the view is displayed, however when I first start up I get a 404 instead of the index.jsp page. I've tried adding a leading slash to index.jsp but that makes no difference.
I must have made a schoolboy error somewhere, but I can't for the life of me see where. Can anyone point it out for me?
Spring MVC 3.2 Tomcat 6 running in STS 2.9.1 servlet 2.5
Many thanks.