SPRING IN ACTION 第4版笔记-第六章Rendering web views-001- Spring支持的View Resolver、InternalResourceViewResolver、JstlView
2016-03-04 20:08
686 查看
一、Spring支持的View Resolver
![](https://oscdn.geek-share.com/Uploads/Images/Content/202001/27/4d83d490396de63a441defb221474b62.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/202001/27/f549c818a469e8b44205fd5b994e407f.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/202001/27/a529c34a456e3bb63c52b6f154074e46.png)
二、InternalResourceViewResolver
Spring supports JSP views in two ways:
InternalResourceViewResolver
Spring provides two JSP tag libraries, one for form-to-model binding and one providing general utility features.
![](https://oscdn.geek-share.com/Uploads/Images/Content/202001/27/f7be2d1fd62d83f716c4ca994c163811.png)
1.在java中定义
2.在xml中定义
By resolving JstlView , the JSTL tags will be given the Locale and any message source configured in Spring.
3.
4.
Whether you use Java configuration or XML , this will ensure that JSTL ’s formatting and message tags will get the Locale and message sources configured in Spring.
![](https://oscdn.geek-share.com/Uploads/Images/Content/202001/27/4d83d490396de63a441defb221474b62.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/202001/27/f549c818a469e8b44205fd5b994e407f.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/202001/27/a529c34a456e3bb63c52b6f154074e46.png)
二、InternalResourceViewResolver
Spring supports JSP views in two ways:
InternalResourceViewResolver
Spring provides two JSP tag libraries, one for form-to-model binding and one providing general utility features.
![](https://oscdn.geek-share.com/Uploads/Images/Content/202001/27/f7be2d1fd62d83f716c4ca994c163811.png)
1.在java中定义
package spittr.web; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.support.ReloadableResourceBundleMessageSource; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.view.InternalResourceViewResolver; @Configuration @EnableWebMvc @ComponentScan("spittr.web") public class WebConfig extends WebMvcConfigurerAdapter { @Bean public ViewResolver viewResolver() { InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix("/WEB-INF/views/"); resolver.setSuffix(".jsp"); return resolver; }
2.在xml中定义
<?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <annotation-driven /> <context:component-scan base-package="spitter" /> <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <beans:property name="prefix" value="/WEB-INF/views/" /> <beans:property name="suffix" value=".jsp" /> </beans:bean> <resources mapping="/resources/**" location="/resources/" /> <!-- <view-controller path="/" view-name="home" /> --> </beans:beans>
By resolving JstlView , the JSTL tags will be given the Locale and any message source configured in Spring.
3.
@Bean public ViewResolver viewResolver() { InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix("/WEB-INF/views/"); resolver.setSuffix(".jsp"); resolver.setViewClass( org.springframework.web.servlet.view.JstlView.class); return resolver; }
4.
<bean id="viewResolver" class="org.springframework.web.servlet.view. InternalResourceViewResolver" p:prefix="/WEB-INF/views/" p:suffix=".jsp" p:viewClass="org.springframework.web.servlet.view.JstlView" />
Whether you use Java configuration or XML , this will ensure that JSTL ’s formatting and message tags will get the Locale and message sources configured in Spring.
相关文章推荐
- Java学习笔记之对象与类
- java并发编程:并发容器之CopyOnWriteArrayList(转)
- [置顶] springmvc接收前台(如ajax)传来的数组list,set等集合图文详解
- JAVA I/O流 之入门
- Java 线程
- Java-匿名内部类
- Java关键字——throws和throw
- Codeforces Round #344 (Div. 2) E - Product Sum(三分 (java))
- Java反射
- Java学习笔记之集合、Iterator、Map
- web网页Eclipse,jsp+Servlet+javaBean,访问Mysql链接数据库
- Java动态 遍历List 时删除List特征元素 异常问题 及解决方案总结
- Java Tips and Best practices to avoid NullPointerException
- Java之求逆矩阵
- Netbeans使用maven下载源码
- Java多线程
- 用java实现在命令方式清屏(native&…
- [转]JAVA打包后读取自身JAR…
- Java的块,静态块,构造函数…
- Java的块,静态块,构造函数…