Question

Everywhere I look always the same explanation pop ups.
Configure the view resolver.

<bean id="viewMappings"
      class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
    <property name="basename" value="views" />
</bean>

And then put a file in the classpath named view.properties with some key-value pairs (don't mind the names).

logout.class=org.springframework.web.servlet.view.JstlView
logout.url=WEB-INF/jsp/logout.jsp

What does logout.class and logout.url mean?
How does ResourceBundleViewResolver uses the key-value pairs in the file?
My goal is that when someone enters the URI myserver/myapp/logout.htm the file logout.jsp gets served.

Was it helpful?

Solution

ResourceBundleViewResolver uses the key/vals in views.properties to create view beans (actually created in an internal application context). The name of the view bean in your example will be "logout" and it will be a bean of type JstlView. JstlView has an attribute called URL which will be set to "WEB-INF/jsp/logout.jsp". You can set any attribute on the view class in a similar way.

What you appear to be missing is your controller/handler layer. If you want /myapp/logout.htm to serve logout.jsp, you must map a Controller into /myapp/logout.htm and that Controller needs to return the view name "logout". The ResourceBundleViewResolver will then be consulted for a bean of that name, and return your instance of JstlView.

OTHER TIPS

To answer your question logout is the view name obtained from the ModelAndView object returned by the controller. If your are having problems you many need the following additional configuration.

You need to add a servlet mapping for *.htm in your web.xml:

    <web-app>
        <servlet>
            <servlet-name>htm</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <oad-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>htm</servlet-name>
            <url-pattern>*.htm</url-pattern>
        </servlet-mapping>
    </web-app>

And if you want to map directly to the *.jsp without creating a custom controller then you need to add the following bean to your Spring context:

    <bean id="urlFilenameController"
        class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top