spring mvc: 资源绑定视图解析器(不推荐)
spring mvc: 资源绑定视图解析器(不推荐)
不适合单控制器多方法访问,有知道的兄弟能否告知。
访问地址:
http://localhost:8080/guga2/hello/index
项目:guga2
包名:springresource
properties文件放在 /WEB-INF/class/下

本例配置文件web.xml, applicationContext.xml, springresource-servlet.xml, views.properties
web.xml
<!--配置文件路径-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param> <!-- 字符过滤器 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- 监听转发 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>springresource</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springresource</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
applicactionContext.xml自动导入bean
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 默认:注解映射支持 -->
<mvc:annotation-driven/>
<!-- 静态资源配置 -->
<mvc:resources location="/pages/**" mapping="/pages/"/> <!-- 自动扫描包名,controller -->
<context:component-scan base-package="springresource"/> </beans>
springresource-servlet.xml引入properties文件
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"> <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
HelloController.java
package springresource; 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
public class HelloController { @RequestMapping(value="/hello/index", method=RequestMethod.GET)
public String index(ModelMap model)
{
model.addAttribute("message", "hello index , Spring MVC资源绑定视图解析器!");
return "hello";
} @RequestMapping(value="/hello/bate", method=RequestMethod.GET)
public String bate(ModelMap model)
{
model.addAttribute("message", "hello bate, Spring MVC资源绑定视图解析器!");
return "hello_bate";
} }
jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>hello index</title>
</head>
<body> hi,${message} </body>
</html>
spring mvc: 资源绑定视图解析器(不推荐)的更多相关文章
- Spring MVC资源绑定视图解析器
ResourceBundleViewResolver使用属性文件中定义的视图bean来解析视图名称. 以下示例显示如何使用Spring Web MVC框架中的ResourceBundleViewRes ...
- spring mvc: 多解析器映射(资源绑定视图解析器 + 内部资源[普通模式/]视图解析器)
spring mvc: 多解析器映射(资源绑定视图解析器 + 内部资源[普通模式/]视图解析器) 资源绑定视图解析器 + 内部资源(普通模式)视图解析器 并存方式 内部资源视图解析器: http:// ...
- Spring MVC的多视图解析器配置及与Freemarker的集成
一.从freemarker谈起 Freemarker使用模板技术进行视图的渲染.自从看了Struts标签.Freemarker.JSTL的性能对比后,我毅然决定放弃Struts标签了!效率太差…… S ...
- spring mvc: 参数方法名称解析器(用参数来解析控制器下的方法)MultiActionController/ParameterMethodNameResolver/ControllerClassNameHandlerMapping
spring mvc: 参数方法名称解析器(用参数来解析控制器下的方法)MultiActionController/ParameterMethodNameResolver/ControllerClas ...
- spring mvc: 属性方法名称解析器(多动作控制器)MultiActionController/ControllerClassNameHandlerMapping/PropertiesMethodNameResolver
spring mvc: 属性方法名称解析器(多动作控制器) 加入控制器是StudentContrller.java,里面有3个方法 index,add,remove 那么访问地址是: http://l ...
- Spring Web MVC 多viewResolver视图解析器解决方案
viewResolver的定义如下: public interface ViewResolver { View resolveViewName(String viewName, Locale loca ...
- Spring MVC-视图解析器(View Resolverr)-资源包视图解析器(Resource Bundle View Resolver)示例(转载实践)
以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_resourcebundleviewresolver.htm 说明:示例基于Spr ...
- Spring MVC参数方法名称解析器
以下示例显示如何使用Spring Web MVC框架来实现多动作控制器的参数方法名称解析器. MultiActionController类可在单个控制器中分别映射多个URL到对应的方法. 所下所示配置 ...
- Spring MVC属性方法名称解析器
以下示例显示如何使用Spring Web MVC框架来实现多动作控制器的属性方法名称解析器. MultiActionController类可在单个控制器中分别映射多个URL到对应的方法. 所下所示配置 ...
随机推荐
- Spring整合jdbc编程
一.Spring对Jdbc的支持 Spring为了提供对Jdbc的支持,在Jdbc API的基础上封装了一套实现,以此建立一个 JDBC 存取框架. 作为 Spring JDBC 框架的核心, ...
- 在PL/SQL中如何让程序暂停几秒钟
在编写PL/SQL中,有时需要程序中暂停几秒钟再继续执行,查了一下,oracle内置有这个功能dbms_lock.sleep(10):不过dbms_lock包需要用户自己安装,演示如下: C:\Doc ...
- [golang note] 流程控制
流程控制 • 流程控制语句作用 ▪ 选择:根据条件跳转到不同的执行序列. ▪ 循环:根据条件反复执行某个序列. ▪ 跳转:据条件返回到某执行序列. • 流程控制语句类型 ▪ 条件语句:关键字为if.e ...
- python16_day20【Django_继续抽屉项目】
一.djangoAdmin和表结构 1.项目名称 python manage startapp web # 前端页面 python manage startapp repository # 只是数 ...
- ruby中的顶层方法
在ruby中写顶层函数的时候,总会有一个问题,self是谁,这些方法是谁的,是什么方法. 如下: p self p self.class def talk p self end talk 输出main ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed
地址:http://codeforces.com/contest/782/problem/B 题目: B. The Meeting Place Cannot Be Changed time limit ...
- linux meta 18.0.1 系统安装nodejs
前置条件是:需要准备sudo apt-get 命令 第一步: 执行命令sudo apt-get install nodejs 即可安装, 之后可使用node -v 查看版本node 版本号 第二步: ...
- I.MX6中PC连接开发板问题
修改板端的文件 添加登录密码: passwd vi /etc/network/interrfaces 在auto eth0下增加auto eth1 如果采用固定ip方式可以在后面增加一段固定ip设置 ...
- SpringMvc接受特殊符号参数被转义
WEB开发时,在前端通过get / post 方法传递参数的时候 如果实参附带特殊符号,后端接收到的值中特殊符号就会被转义 例如该请求: http://localhost:10001/demo/in ...
- 20145333茹翔 《Java程序设计》实验四 实验报告
实验要求 完成实验.撰写实验报告,实验报告以博客方式发表在博客园,注意实验报告重点是运行结果,遇到的问题(工具查找,安装,使用,程序的编辑,调试,运行等).解决办法(空洞的方法如"查网络&q ...