How to configure ResourceBundleViewResolver in Spring Framework 2.0

Everywhere I look always the same explanation of pop-ups.
Configure the recognizer.

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

And then put the file in the classpath named view.properties with some key-value pairs (not against the names).

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

What do logout.class and logout.url ?
How does ResourceBundleViewResolver use key-value pairs in a file?
My goal is that when someone enters the myserver/myapp/logout.htm URI, the myserver/myapp/logout.htm file is logout.jsp .

+4
source share
2 answers

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

What seems missing to you is your controller / handler level. If you want /myapp/logout.htm to serve logout.jsp, you must map the controller to /myapp/logout.htm and that the controller needs to return a name like "logout". Then a ResourceBundleViewResolver will be processed for the bean of this name and it will return your JstlView instance.

+5
source

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

You need to add the servlet mapping for *.htm to 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 *.jsp without creating a custom controller, you need to add the following bean to the Spring context:

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

Source: https://habr.com/ru/post/1276954/


All Articles