views:

278

answers:

1

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.

UPDATE: I just verified that if I rename my .jsp files to something else (.jst) and update the viewResolver accordingly, than it all works. Apparently if the view is resolved to a file with extension .jsp, spring tries to forward the view to another controller.

+2  A: 

if it's really not working with .jsp extensions (although i can't personally see any reason for that), you could try using http://tuckey.org/urlrewrite/ to do a rewrite of the urls first.

oedo