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>

A few important points to note:

  • org.springframework.web.servlet.view.InternalResourceViewResolver: A view resolver supporting JSPs. JstlView is typically used. It also supports tiles with a TilesView.
  • <property name="prefix"> ...

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.