How can I map a spring controller to a url with .jsp extension?
- by Matteo Caprari
Hi.
We are in the process of migrating a jsp-only application to Spring-MVC. For various reasons we can't change the extension of the current pages. (calls to login.jsp need to handled by a spring controller that will use a jsp file as view).
We are doing this iteratively, so some pages need to stay jsp files (calls to welcome.jsp won't be handled by a controller).
To do that I mapped both the DispatcherDervlet and the HandlerMapping to *.jsp, and configured the JstlView in the standard way.
Unfortunately, if I browse to //login.jsp I get an error saying
<No mapping found for HTTP request with URI [/<context>/WEB-INF/jsp/login.jsp] in DispatcherServlet with name 'spring'>
It all works if I change .jsp to any other extension in DispatcherServlet and HandlerMapping.
web.xml:
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
spring-servlet.xml:
<!-- View resolver -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<!-- URL Mapping -->
<bean id="publicUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/login.jsp" value-ref="loginController"/>
</map>
</property>
</bean>
Thanks a lot.