以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_resourcebundleviewresolver.htm

说明:示例基于Spring MVC 4.1.6。

ResourceBundleViewResolver用于使用在属性文件中定义的视图bean来解析视图名称。以下示例显示如何使用Spring Web MVC框架使用ResourceBundleViewResolver。

TestWeb-servlet.xml

<bean class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
<property name="basename" value="views" />
</bean>
  1. basename是指包含视图的资源束的名称。资源束的默认名称是views.properties,可以使用basename属性覆盖。

views.properties

hello.(class)=org.springframework.web.servlet.view.JstlView
hello.url=/WEB-INF/jsp/hello.jsp

例如,使用上面的配置,如果是URI

  1. /hello被请求,DispatcherServlet将请求转发到由在您的view.properties中的bean hello定义的hello.jsp。

  2. 这里“hello”是要匹配的视图名称。类是指视图类型,url是视图的位置。

首先,让我们使用Eclipse IDE,并按照以下步骤使用Spring Web Framework开发基于动态窗体的Web应用程序:

步骤 描述
1 创建一个名为TestWeb的项目,在一个包com.tutorialspoint下,如Spring MVC - Hello World Example章节所述。
2 在com.tutorialspoint包下创建一个Java类HelloController。
3 在jsp子文件夹下创建一个视图文件hello.jsp。
4 在src文件夹下创建一个属性文件views.properties。
5 下载JSTL库jstl.jar。把它放在你的CLASSPATH中。
6 最后一步是创建所有源和配置文件的内容并导出应用程序,如下所述。

HelloController.java

package com.tutorialspoint;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.ui.ModelMap; @Controller
@RequestMapping("/hello")
public class HelloController{ @RequestMapping(method = RequestMethod.GET)
public String printHello(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!"); return "hello";
} }

TestWeb-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:component-scan base-package="com.tutorialspoint" /> <bean class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
<property name="basename" value="views" />
</bean>
</beans>

views.properties

hello.(class)=org.springframework.web.servlet.view.JstlView
hello.url=/WEB-INF/jsp/hello.jsp

hello.jsp

<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h2>${message}</h2>
</body>
</html>

完成创建源文件和配置文件后,导出应用程序。右键单击应用程序,然后使用Export > WAR File选项,并将您的HelloWeb.war文件保存在Tomcat的webapps文件夹中。

现在启动您的Tomcat服务器,并确保您可以使用标准浏览器从webapps文件夹访问其他网页。现在尝试访问URL http://localhost:8080/HelloWeb/hello,如果您的Spring Web应用程序一切正常,您应该看到以下结果:

Maven示例:

https://github.com/easonjim/5_java_example/tree/master/springmvc/tutorialspoint/test24

Spring MVC-视图解析器(View Resolverr)-资源包视图解析器(Resource Bundle View Resolver)示例(转载实践)的更多相关文章

  1. Spring MVC-视图解析器(View Resolverr)-XML视图解析器(Xml View Resolver)示例(转载实践)

    以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_xmlviewresolver.htm 说明:示例基于Spring MVC 4.1 ...

  2. Spring MVC程序中怎么得到静态资源文件css,js,图片文件的路径问题

    问题描述 在用springmvc开发应用程序的时候.对于像我一样的初学者,而且还是自学的人,有一个很头疼的问题.那就是数据都已经查出来了,但是页面的样式仍然十分简陋,加载不了css.js,图片等资源文 ...

  3. Spring MVC 拦截 js,css,png 等资源

    springMVC的<mvc:resources mapping="***" location="***">标签是在spring3.0.4出现的,主 ...

  4. 解决 spring mvc 3.0 结合 hibernate3.2 使用<tx:annotation-driven>声明式事务无法提交的问题(转载)

    1.问题复现 spring 3.0 + hibernate 3.2 spring mvc使用注解方式:service使用@service注解 事务使用@Transactional 事务配置使用 < ...

  5. spring mvc 自定义handler不拦截静态资源

    处理静态资源的handler和处理Controller请求中的handler不同,对应的Interceptor也不同 查找对应handler是在DispatcherServlet中 因此一些自定义的I ...

  6. 基于注解的Spring MVC整合Hibernate(所需jar包,spring和Hibernate整合配置,springMVC配置,重定向,批量删除)

    1.导入jar watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdG90b3R1enVvcXVhbg==/font/5a6L5L2T/fontsize/400 ...

  7. Spring MVC视图解析器(ViewResolver)

    视图解析器(ViewResolver)是 Spring MVC 的重要组成部分,负责将逻辑视图名解析为具体的视图对象.Spring MVC 提供了很多视图解析类,其中每一项都对应 Java Web 应 ...

  8. Spring mvc解析

    方案时间 ,写代码时间 ,解决技术难点时间 , 自测时间,解决bug时间 , 联调时间 ,数据库优化,代码走查1个接口:2个小时 把那个字段再复原回来,不然兼容性不强还有一个刷数据的接口 public ...

  9. Spring MVC -- 验证器

    输入验证是Spring处理的最重要Web开发任务之一.在Spring MVC中,有两种方式可以验证输入,即利用Spring自带的验证框架,或者利用JSR 303实现.本篇博客将介绍这两种输入验证方法. ...

随机推荐

  1. Win7 + VS2015 + Python3.6编译

    0. 下载安装hg. http://bitbucket.org/tortoisehg/files/downloads/tortoisehg-4.0.1-x64.msi 1. 下载Python3.6源代 ...

  2. hbuilder中的 http://www.w3.org/TR/html4/frameset.dtd

    <!-- This is the HTML 4.01 Frameset DTD, which should be used for documents with frames. This DTD ...

  3. 【Leetcode 86】 Partition List

    问题描述: 给定一个list, 将所有小于x的node放到左边,剩下的保持原样. 问题解决: 闲的无聊,用c++和python都做了一遍. 代码如下: # Definition for singly- ...

  4. Elasticsearch之sense插件的安装(图文详解)

    sense插件可以方便的执行rest请求,但是中文输入的体验不是很好. 安装sense只需要在Kibana端安装插件即可,插件会自动安装到kibana的应用菜单中. [hadoop@master ki ...

  5. vue-cli的创建、基本配置和遇到的问题总结

    vue-cli的创建及基本配置 1. 创建 vue-cli 项目 确保本地安装了最新版本的nodejs环境(会自带npm环境); 全局安装vue-cli,命令:npm i -g vue-cli 创建项 ...

  6. SAS进阶《深入解析SAS》之对多数据集的处理

    SAS进阶<深入解析SAS>之对多数据集的处理 1. 数据集的纵向串接: 数据集的纵向串接指的是,将两个或者多个数据集首尾相连,形成一个新的数据集. 据集的横向合并: 数据集的横向合并,指 ...

  7. Win32基础知识整理

    1.定义字符串 在资源新建String table,增加新字符串: (win32加载) TCHAR tcIDName[255]=_T(""); LoadString(hInstan ...

  8. 【MySQL】RPM包安装

    操作系统:Red Hat Enterprise Linux Server release 6.5 Mysql安装包:MySQL-5.6.35-1.linux_glibc2.5.x86_64.rpm-b ...

  9. JS高级——原型链

    构造函数 构造函数是特殊的函数,里面没有returen返回值 new的过程中,会自动将对象返回,不需要return new的过程中,会执行函数中的代码,会将创建的对象赋值给构造函数中的this 基本概 ...

  10. dotnetnuke 获得List 属性

    new DotNetNuke.Common.Lists.ListController().GetListEntryInfo("DataType","Text") ...