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: 资源绑定视图解析器(不推荐)的更多相关文章

  1. Spring MVC资源绑定视图解析器

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

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

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

  3. Spring MVC的多视图解析器配置及与Freemarker的集成

    一.从freemarker谈起 Freemarker使用模板技术进行视图的渲染.自从看了Struts标签.Freemarker.JSTL的性能对比后,我毅然决定放弃Struts标签了!效率太差…… S ...

  4. spring mvc: 参数方法名称解析器(用参数来解析控制器下的方法)MultiActionController/ParameterMethodNameResolver/ControllerClassNameHandlerMapping

    spring mvc: 参数方法名称解析器(用参数来解析控制器下的方法)MultiActionController/ParameterMethodNameResolver/ControllerClas ...

  5. spring mvc: 属性方法名称解析器(多动作控制器)MultiActionController/ControllerClassNameHandlerMapping/PropertiesMethodNameResolver

    spring mvc: 属性方法名称解析器(多动作控制器) 加入控制器是StudentContrller.java,里面有3个方法 index,add,remove 那么访问地址是: http://l ...

  6. Spring Web MVC 多viewResolver视图解析器解决方案

    viewResolver的定义如下: public interface ViewResolver { View resolveViewName(String viewName, Locale loca ...

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

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

  8. Spring MVC参数方法名称解析器

    以下示例显示如何使用Spring Web MVC框架来实现多动作控制器的参数方法名称解析器. MultiActionController类可在单个控制器中分别映射多个URL到对应的方法. 所下所示配置 ...

  9. Spring MVC属性方法名称解析器

    以下示例显示如何使用Spring Web MVC框架来实现多动作控制器的属性方法名称解析器. MultiActionController类可在单个控制器中分别映射多个URL到对应的方法. 所下所示配置 ...

随机推荐

  1. SAP Idoc 事务码

    SALE Display ALE Customizing SM59 RFC Destinations (Display/Maintain) BD64 Maintenance of Distributi ...

  2. rtsp/rtmp/hls/onvif测试源以及ffmpeg在流媒体方面的应用

    一.rtsp/rtmp/hls/onvif测试源 1. rtsp rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov 2.rtmp rtmp://l ...

  3. mysql监控优化(三)慢查询

    顾名思义,慢查询日志中记录的是执行时间较长的query,也就是我们常说的slowquery,通过设--log-slow-queries[=file_name]来打开该功能并设置记录位置和文件名.慢查询 ...

  4. jmeter使用代理服务器录制脚本端口号被占用

    初学jmeter工具,在设置端口号时,使用8080,IE设置的局域网端口也为8080,启动代理服务器时,提示:Could not create script recorder-port in use. ...

  5. 【转帖】C++经典书籍汇总

    TCPL和D&E 1:Bjarne Stroustrup, The C++ Programming Language (Special 3rd Edition) <C++ 程序设计语言( ...

  6. PHPCMS 修改后台路径简便方法

    之前在网上找了很多关于修改phpcms后台路径的修改方法,但是都太繁琐(个人感觉),终于找到了一个相对简单的修改方法,在这里和大家分享一下,希望互相学习. 第一步:在网站根目录创建一个文件夹,以后就要 ...

  7. kubernetes上安装MongoDB-3.6.5集群副本集方式

    一.安装部署: 想直接一步创建集群的小伙伴直接按以下步骤安装(再往后是记录自己出过的错): 1.生成docker镜像: docker build -t 144.202.127.156/library/ ...

  8. Swoole学习(五)Swoole之简单WebSocket服务器的创建

    环境:Centos6.4,PHP环境:PHP7 服务端代码 <?php //创建websocket服务器 $host = '0.0.0.0'; $port = ; $ws = new swool ...

  9. 20145313张雪纯 《Java程序设计》第6周学习总结

    20145313张雪纯 <Java程序设计>第6周学习总结 教材学习内容总结 将数据从来源中取出,可以使用输入串流:将数据写入目的地,可以使用输出串流. 输入串流代表对象为java.io. ...

  10. 4.9版本的linux内核中eeprom存储芯片at24c512的驱动源码在哪里

    答:drivers/misc/eeprom/at24.c,内核配置项为CONFIG_EEPROM_AT24 Location: -> Device Drivers -> Misc devi ...