官术网_书友最值得收藏!

View resolvers

We saw the purpose of the first two tags that are specified within the web application context configuration file:

<mvc:annotation-driven />
<context:component-scan base-package="com.packt.webstore" />

Based on these tags, Spring creates the necessary beans to handle a web request and also creates beans for all the @Controller classes. However, to run a Spring MVC application successfully, Spring needs one more bean; this bean is called a view resolver.

A view resolver helps the dispatcher servlet identify the views that have to be rendered as the response for a specific web request. Spring MVC provides various view resolver implementations to identify views, and InternalResourceViewResolver is one such implementation. The final tag in the web application context configuration is the bean definition for the InternalResourceViewResolver class as follows:

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
   <property name="suffix" value=".jsp" />
</bean>

Through the preceding bean definition in the web application context configuration, we instruct Spring MVC to create a bean for the InternalResourceViewResolver class (org.springframework.web.servlet.view.InternalResourceViewResolver). We will learn more about the view resolver in Chapter 5, Working with View Resolver.

主站蜘蛛池模板: 五河县| 凤城市| 县级市| 桐乡市| 潞城市| 高碑店市| 牟定县| 吴川市| 鄂托克前旗| 浦江县| 阿合奇县| 凤庆县| 西丰县| 田东县| 吴桥县| 华蓥市| 靖江市| 宝坻区| 西藏| 汕尾市| 花莲市| 杂多县| 孙吴县| 定陶县| 台中市| 松滋市| 岳池县| 泸州市| 广州市| 眉山市| 澄迈县| 兰州市| 雅江县| 彝良县| 西充县| 栾川县| 舟曲县| 改则县| 称多县| 离岛区| 图木舒克市|