views:

4572

answers:

4

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.

+2  A: 

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.

Craig
A: 
bmatthews68
A: 

Thanks for the information but i on using the configuration suggested i am getting : javax.servlet.ServletException: No adapter for handler [org.springframework.web.servlet.view.ResourceBundleViewResolver@9ed91f]: Does your handler implement a supported interface like Controller? org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:1086) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:873) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:808) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431) javax.servlet.http.HttpServlet.service(HttpServlet.java:690) javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

Changes done were:

example-servlet.xml

<bean id="logoutViewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">

 <property name="basename">
  <value>views</value>
 </property>
</bean>

Url Mapping is done:

bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">

prop key="/logout.htm">logoutViewResolver

/bean>


view.properties:

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

Please suggest how to fix the problem.

A: 

You can find an example on this here. Spring Tutorial