SpringMVC ------JstlView

摘要: 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>
时间: 2024-08-05 07:08:22

SpringMVC ------JstlView的相关文章

JSTLView快速国际化(SpringMVC)

JSTLView:快速国际化:只要导入了jstl的jar包,以前默认创建的InternalResouceView都会被使用jstlView替代: 国际化的新步骤: 1).写好国际化资源文件 il118_en_US.properties il118_zh_CN.properties 2).在SpringMVC配置文件中配置管理国际化资源文件的消息管理器组件 <!-- 注册一个国际化资源管理器:id必须是messageSource --> <bean id="messageSour

SpringMvc源码阅读View之JstlView如何渲染视图(十)

类图 此处只截取了部分 接口 public interface View { String RESPONSE_STATUS_ATTRIBUTE = org.springframework.web.servlet.View.class.getName() + ".responseStatus"; String PATH_VARIABLES = org.springframework.web.servlet.View.class.getName() + ".pathVariabl

SpringMVC 入门

1. SpringMVC 是什么 Spring MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解耦,基于请求驱动指的就是使用请求-响应模型,框架的目的就是帮助我们简化开发,Spring MVC也是要简化我们日常Web开发的. Spring MVC也是服务到工作者模式的实现,但进行可优化.前端控制器是DispatcherServlet:应用控制器其实拆为处理器映射器(Handler Mapping)进行处理器

基于Spring+SpringMVC+Mybatis的Web系统搭建

主要的后端架构:Spring+SpringMVC+Mybatis+Shiro+Maven  IDE:IntelliJ IDEA 15.0.2 jdk:1.8.0_66 系统完整源码 https://github.com/Wellat/Factor 系统目录结构 跑起来效果 搭建步骤 1.用Idea创建maven项目 2.配置pom.xml文件,添加依赖 1 <?xml version="1.0" encoding="UTF-8"?> 2 <proj

springmvc事务回滚失效

转载:http://blog.csdn.net/z69183787/article/details/37819831 前文提到,最新换了框架,新项目用SpringMVC + Spring JdbcTemplate.搭框架时,发现了一个事务无法正常回滚的问题,记录如下: 首先展示问题: Spring applicationContext.xml配置: [html] view plaincopy <bean id="dataSource" class="org.spring

Spring框架:SpringMVC详解

SpringMVC的工作流程.最先接触到请求的是DispatcherServlet,它会将请求根据配置文件转发到控制器,控制器返回视图名称和一个Model表示处理结果.DispatcherServlet再将处理结果发送给视图模板引擎,由它进行页面的渲染.下图是整个过程. 基本配置 声明servlet.首先要在web.xml中声明Spring的Servlet,代码如下: <servlet> <servlet-name>spring</servlet-name> <s

SpringMVC中简单的上传

项目截图 需要导入的基本包有Spring所有的包加上Apache支持上传的包 web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instan

Maven搭建SpringMVC+Hibernate项目详解

前言 今天复习一下SpringMVC+Hibernate的搭建,本来想着将Spring-Security权限控制框架也映入其中的,但是发现内容太多了,Spring-Security的就留在下一篇吧,这篇主要搭建SpringMVC4.1.4和Hibernate4.3.8,之前也打了好多SpringMVC的,这部分已经非常的熟悉了,毕竟业开发过一年多SpringMVC的,这次持久层采用Hibernate,数据源采用c3p0,数据库暂采用MySQL,主要是想复习一下Hibernate.搭建Spring

java:Springmvc框架2(Ajax,Interceptor,)

1.springmvcAjax: springmvc.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="ht