码迷,mamicode.com
首页 > 编程语言 > 详细

SpringMVC ------JstlView

时间:2017-04-10 19:35:26      阅读:303      评论:0      收藏:0      [点我收藏+]

标签:响应   摘要   port   耦合   property   控制器   java   扩展   服务   

摘要: Spring为展现层提供的基于MVC设计理念的优秀的Web框架,是目前最主流的MVC框架之一 。Spring3.0后全面超越Struts,成为最优秀的MVC框架 。SpringMVC通过一套MVC注解,让POJO成为处理请求的控制器,而无须事先任何接口。 支持REST风格的URL请求。 采用了松散耦合可插拔组建结构,比其他MVC框架更具扩展性和灵活性。 本文基于Sping4.x.

    若项目中使用JSTL,则SpringMVC会自动把视图由InternalResourceView转为JstlView

    若使用JSTL的fmt标签则需要在SpringMVC的配置文件中配置国际化资源文件。

<bean id="messageSource" class"org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename" value="i18n"></property>
</bean>

-------------------------------------分割线--------------------------------------------------------------------------

    若希望直接响应通过SpringMVC渲染的页面,可以使用mvc:view-controller标签实现

    path是访问succes.jsp页面的映射路径。view-name是视图名字即success.jsp

    页面不需要进行操作,直接访问,不需要进过handler的页面。

<mvc:view-controller path="springmvc/testJstlView" view-name="success"/>

注意使用这个标签,一般都会配合使用

<mvc:annotation-driven></mvc:annotation-driven>

如果不配置,那么如果你有handler也是转发到这个success视图上面,服务器会提示404,找不到该页面。

------------------------------------------分割线-----------------------------------------------------------------------

    先加入jstl库文件。

    编写国际化资源文件 i18n_zh_CN.properties ,i18n.properties ,i18n_en_US.properties 

    这里我们编写 i18n_en_US.properties文件

i18n.username=username
i18n.password=password

在jsp页面导入fmt标签。

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    
    //编写jsp代码
    <fmt:message key="i18n.username"></fmt:message>
    <br/>
    <fmt:message key="i18n.password" ></fmt:message>

在spring.xml中配置国际化资源文件

<bean id="messageSource" class"org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename" value="i18n"></property>
</bean>

SpringMVC ------JstlView

标签:响应   摘要   port   耦合   property   控制器   java   扩展   服务   

原文地址:http://www.cnblogs.com/hihtml5/p/6690281.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!