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

说明:示例基于Spring MVC 4.1.6。

InternalResourceViewResolver用于将提供的URI解析为实际的URI。以下示例显示如何使用Spring Web MVC框架使用InternalResourceViewResolver。InternalResourceViewResolver允许使用请求映射网页。

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";
} }
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>

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

  1. /hello被请求,DispatcherServlet将请求转发到前缀+ view-name + suffix = /WEB-INF/jsp/hello.jsp。

首先,让我们使用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 最后一步是创建所有源和配置文件的内容并导出应用程序,如下所述。

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.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean> </beans>

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选项,并将您的TestWeb.war文件保存在Tomcat的webapps文件夹中。

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

Maven示例:

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

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

  1. spring mvc:内部资源视图解析器2(注解实现)@Controller/@RequestMapping

    spring mvc:内部资源视图解析器2(注解实现)  @Controller/@RequestMapping 访问地址: http://localhost:8080/guga2/hello/goo ...

  2. spring mvc:内部资源视图解析器(注解实现)@Controller/@RequestMapping

    spring mvc:内部资源视图解析器(注解实现)@Controller/@RequestMapping 项目访问地址: http://localhost:8080/guga2/hello/prin ...

  3. Spring MVC内部资源视图解析器

    InternalResourceViewResolver用于将提供的URI解析为实际URI.下面的示例演示如何在Spring Web MVC框架中使用SpringResultViewResolver. ...

  4. Spring MVC-视图解析器(View Resolverr)-资源包视图解析器(Resource Bundle View Resolver)示例(转载实践)

    以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_resourcebundleviewresolver.htm 说明:示例基于Spr ...

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

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

  6. springmvc:BeanNameViewResolver访问内部资源视图对象和访问外部资源视图对象

    <!-- 处理器映射器 --> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerM ...

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

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

  8. SpringMvc之handler深入AbstractControllerhe和MultiActionController和内部资源视图解析器

    AbstractControllerhe 若处理器继承自AbstractController类,那么该控制器就具有了一些新功能.因为AbstractController类还继承自一个父类WebCont ...

  9. spring mvc: 多解析器映射(资源绑定视图解析器 + 内部资源[普通模式/]视图解析器)

    spring mvc: 多解析器映射(资源绑定视图解析器 + 内部资源[普通模式/]视图解析器) 资源绑定视图解析器 + 内部资源(普通模式)视图解析器 并存方式 内部资源视图解析器: http:// ...

随机推荐

  1. 阿拉伯数字1与英语字母l造成的代码bug

    <img src="./images/demo3/1a.png" /> <img src="./images/demo3/la.png" /& ...

  2. JavaScript Date 日期操作

    在前端工程师的道路上,可能有时候需要与时间来打交道,下面我们来看一下日常对日期的操作,今天我们介绍的是Day.js插件 Day.js 是一个轻量的处理时间和日期的 JavaScript 库,和 Mom ...

  3. redis cluster集群理解

    Redis Cluster集群 一.redis-cluster设计 Redis集群搭建的方式有多种,例如使用zookeeper等,但从redis 3.0之后版本支持redis-cluster集群,Re ...

  4. 去掉myeclipse的预览窗口

    1,选择菜单: windows -> preferences2,在弹出窗口中选择General-> Editors -> FileAssociations3,在上方框内选择*.jsp ...

  5. 话说:Hibernate二级缓存

    Hibernate缓存分类: 一.Session缓存(又称作事务缓存):Hibernate内置的,不能卸除. 缓存范围:缓存只能被当前Session对象访问.缓存的生命周期依赖于Session的生命周 ...

  6. JS——三个运用正则的方法

    trim().replace().search() <script> //trim();去除前后的空格 var str = " 你好 我很好! "; console.l ...

  7. CNN结构:HSV中的饱和度解析

    参考:颜色的前世今生-饱和度 详解,划重点- 关键这个"纯"是指什么? 是指颜色明亮么?明度高的颜色看起来也明亮啊,不一定纯度高啊- 是说颜色鲜艳么?颜色 "不鲜艳&qu ...

  8. python os os.path模块学习笔记

    #!/usr/bin/env python #coding=utf-8 import os #创建目录 os.mkdir(r'C:\Users\Silence\Desktop\python') #删除 ...

  9. CAD调用移动命令

    主要用到函数说明: _DMxDrawX::SendStringToExecuteFun 把命令当着函数执行,可以传参数,详细说明如下: 参数 说明 IDispatch* pParam 命令参数,IMx ...

  10. 铁大FaceBook的使用体验副本

    铁大FaceBook是一个类似QQ和微信等聊天程序的缩小版网站,并且其针对领域较为狭窄:即只针对校园的学生和导员等人员.但其有值得推广的潜力性和可能性. 对于使用它的体验:第一点我感觉这个网站的界面很 ...