Spring MVC-视图解析器(View Resolverr)-资源包视图解析器(Resource Bundle View Resolver)示例(转载实践)
以下内容翻译自: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>
basename是指包含视图的资源束的名称。资源束的默认名称是views.properties,可以使用basename属性覆盖。
views.properties
hello.(class)=org.springframework.web.servlet.view.JstlView
hello.url=/WEB-INF/jsp/hello.jsp
例如,使用上面的配置,如果是URI
/hello被请求,DispatcherServlet将请求转发到由在您的view.properties中的bean hello定义的hello.jsp。
这里“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)示例(转载实践)的更多相关文章
- Spring MVC-视图解析器(View Resolverr)-XML视图解析器(Xml View Resolver)示例(转载实践)
以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_xmlviewresolver.htm 说明:示例基于Spring MVC 4.1 ...
- Spring MVC程序中怎么得到静态资源文件css,js,图片文件的路径问题
问题描述 在用springmvc开发应用程序的时候.对于像我一样的初学者,而且还是自学的人,有一个很头疼的问题.那就是数据都已经查出来了,但是页面的样式仍然十分简陋,加载不了css.js,图片等资源文 ...
- Spring MVC 拦截 js,css,png 等资源
springMVC的<mvc:resources mapping="***" location="***">标签是在spring3.0.4出现的,主 ...
- 解决 spring mvc 3.0 结合 hibernate3.2 使用<tx:annotation-driven>声明式事务无法提交的问题(转载)
1.问题复现 spring 3.0 + hibernate 3.2 spring mvc使用注解方式:service使用@service注解 事务使用@Transactional 事务配置使用 < ...
- spring mvc 自定义handler不拦截静态资源
处理静态资源的handler和处理Controller请求中的handler不同,对应的Interceptor也不同 查找对应handler是在DispatcherServlet中 因此一些自定义的I ...
- 基于注解的Spring MVC整合Hibernate(所需jar包,spring和Hibernate整合配置,springMVC配置,重定向,批量删除)
1.导入jar watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdG90b3R1enVvcXVhbg==/font/5a6L5L2T/fontsize/400 ...
- Spring MVC视图解析器(ViewResolver)
视图解析器(ViewResolver)是 Spring MVC 的重要组成部分,负责将逻辑视图名解析为具体的视图对象.Spring MVC 提供了很多视图解析类,其中每一项都对应 Java Web 应 ...
- Spring mvc解析
方案时间 ,写代码时间 ,解决技术难点时间 , 自测时间,解决bug时间 , 联调时间 ,数据库优化,代码走查1个接口:2个小时 把那个字段再复原回来,不然兼容性不强还有一个刷数据的接口 public ...
- Spring MVC -- 验证器
输入验证是Spring处理的最重要Web开发任务之一.在Spring MVC中,有两种方式可以验证输入,即利用Spring自带的验证框架,或者利用JSR 303实现.本篇博客将介绍这两种输入验证方法. ...
随机推荐
- maven+ssm+oracle实现简单的增删改查
首先看一下项目结构 第一步先导入jar包 pom.xml <properties> <spring.version>4.3.18.RELEASE</spring.vers ...
- 6月来了,Java还是第一!
2019年6月了,话说现在很多小孩子都开始接触幼儿编程了,我也经常看到幼儿编程的广告,编程门槛真的是越来越低. 除此之外,也有大量其他行业的从业者想转软件开发的,编程那么广,语言那么多,那么在这么多编 ...
- easyui- comobo 详细讲解
具体代码实现 @{ ViewBag.Title = "人员查找"; ViewBag.LeftWidth = "200px"; ViewBag. ...
- Centos 7 安装google 浏览器(yum 方式)
过程: 1 vim /etc/yum/repo.s/google_chrome.repo 2 添加如下内容: [google-chrome] name=google-chrome ...
- linux的touch命令
linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件. 1.命令格式: touch [选项]... 文件... 2.命令参数: -a ...
- .net Jquery动态显示当前时间
<span id="Timer"></span> <script type="text/javascript"> $(fun ...
- Listview模板
每次写listview都要翻以前的代码,好烦.所以记下模板,方便下次的使用. xml文件部分代码: <ListView android:id="@+id/listview" ...
- ASP.NET MVC 二维码生成(ThoughtWorks.QRCode)
原文地址http://www.cnblogs.com/jys509/p/4592539.html
- oracle 用户的操作
语法: CREATE USER user IDENTIFIED { BY password | EXTERNALLY [ AS 'certificate_DN' ] ...
- 【YOLO】实时对象检测使用体验
官网:https://pjreddie.com/darknet/yolo/ 以下全部在服务器上完成,服务器上是有opencv等. 1.安装Darknet git clone https://githu ...