Configuring a View resolver

A View resolver resolves a View name to the actual JSP page. The View name in this example is welcome, and we would want it to resolve to /WEB-INF/views/welcome.jsp.

A View resolver can be configured in the Spring context, /WEB-INF/user-web-context.xml. Here's the code snippet for that:

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 

<property name="prefix">
<value>/WEB-INF/views/</value>
</property>

<property name="suffix">
<value>.jsp</value>
</property>

</bean>

The following definitions explain the code in detail:

  • org.springframework.web.servlet.view.InternalResourceViewResolver: This is a View resolver supporting JSPs. JstlView is typically used. It also supports tiles with TilesView.
  • <property name="prefix"> <value>/WEB-INF/views/</value> </property><property name="suffix"> <value>.jsp</value> </property>: This maps the prefix and suffix to be used by a View resolver. A View resolver takes the string from the controller method and resolves to the View—prefix + viewname + suffix. So, the View name, welcome, is resolved to /WEB-INF/views/welcome.jsp.

Here is a screenshot of how this would appear on screen when the URL is hit:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset