spring mvc: 可参数化的视图控制器(在配置中指定jsp文件)MultiActionController/SimpleUrlHandlerMapping/ParameterizableViewController
spring mvc: 可参数化的视图控制器(在配置中指定jsp文件)MultiActionController/SimpleUrlHandlerMapping/ParameterizableViewController
访问地址如下:
http://localhost:8080/项目/index.html
注意:变量不能解析,不知道为啥。
StudentController.java是在springtest包下面
xml中用到的类,
org.springframework.web.servlet.handler.SimpleUrlHandlerMapping
org.springframework.web.servlet.mvc.ParameterizableViewController
java-controller中用到的类
org.springframework.web.servlet.mvc.multiaction.MultiActionController;
配置文件web.xml, applicationContext.xml,xxxx-servlet.xml
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>springtest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springtest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
applicationContext.xml
<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="springmvc"/> </beans>
springtest-servlet.xml
<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"> <!-- viewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>index.html=studentController</value>
</property>
</bean>
<bean id="studentController" class="org.springframework.web.servlet.mvc.ParameterizableViewController">
<property name="viewName" value="student_index"/>
</bean> </beans>
StudentController.java
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController; public class StudentController extends MultiActionController { public ModelAndView home(HttpServletRequest request, HttpServletResponse response)
{
ModelAndView model = new ModelAndView("student_index");
model.addObject("message", "home");
model.addObject("title", "student");
return model;
} }
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>home-student</title>
</head>
<body> ${title}
<br> hi,
${message} </body>
</html>
spring mvc: 可参数化的视图控制器(在配置中指定jsp文件)MultiActionController/SimpleUrlHandlerMapping/ParameterizableViewController的更多相关文章
- Spring MVC可参数化的视图控制器
以下示例显示如何使用Spring Web MVC框架来实现多动作控制器的可参数化视图控制器.可参数化视图允许将请求映射到网页. 所下所示配置 - import javax.servlet.http.H ...
- Spring MVC体系结构和处理请求控制器
Spring MVC体系结构和处理请求控制器 一:MVC设计模式: (1.)数据访问接口:DAO层 (2.)处理业务逻辑层:Service层 (3.)数据实体:POJO (4.)负责前段请求接受并处理 ...
- Spring MVC 实例:Excel视图的使用
对于Excel而言,Spring MVC所推荐的是使用AbstractXlsView,它实现了视图接口,从其命名也可以知道它只是一个抽象类,不能生成实例对象.它自己定义了一个抽象方法——buildEx ...
- (4.1)Spring MVC执行原理和基于Java的配置过程
一.Spring MVC执行原理和基于Java配置的配置过程 (一)Spring MVC执行过程,大致为7步. 所有的请求都会经过Spring的一个单例的DispacherServlet. Dispa ...
- Spring MVC(一)五大核心组件和配置
一,五大核心组件 1.DispatcherServlet 请求入口 2.HandlerMapping 请求派发,负责请求和控制器建立一一对应的关系 3.Controller 处理器 4.Mod ...
- Spring MVC执行原理和基于Java的配置过程
一.Spring MVC执行原理和基于Java配置的配置过程 (一)Spring MVC执行过程,大致为7步. 所有的请求都会经过Spring的一个单例的DispacherServlet. Dispa ...
- Spring MVC + Security 4 初体验(Java配置版)
spring Version = 4.3.6.RELEASE springSecurityVersion = 4.2.1.RELEASE Gradle 3.0 + Eclipse Neno(4.6) ...
- spring MVC 使用 hibernate validator验证框架,国际化配置
spring mvc使用hibernate validator框架可以实现的功能: 1. 注解java bean声明校验规则. 2. 添加message错误信息源实现国际化配置. 3. 结合sprin ...
- 0057 Spring MVC如何获取HTTP请求头信息--URL中的动态参数--@RequestHeader--@CookieValue--@PathVariable
获取HTTP请求头信息 一个HTTP请求除了有参数和实体内容外还有HTTP请求头信息,Spring MVC也可以获取这部分信息 @RequestHeader解可以将请求头信息映射到处理方法的形参上 @ ...
随机推荐
- c#在线手册汇总
1. c#中文手册(脚本之家) http://shouce.jb51.net/net/
- XDU 1140 寻找万神(字符串匹配)
学会strstr的使用 strstr(str1,str2)函数用于判断字符串str2是否是str1的子串.如果是,则该函数返回str2在str1中首次出现的地址:否则,返回NULL. #include ...
- 虚拟机Linux系统忘记密码的情况下,修改root或其他用户密码
使用场景 linux管理员忘记root密码,需要进行找回操作. 注意事项:本文基于centos7环境进行操作,由于centos的版本是有差异的,继续之前请确定好版本. 步骤 一.重启系统,在开机过程中 ...
- yarn nodes label (yarn 划分子集群)
yarn node labels 特性给节点打标签可以把特性类似的节点分成一组,这样可以指定特定的应用执行在特定的机器群上.现在我们只支持节点划分,1.一个节点仅能有一个节点划分,即一个节点只能打一个 ...
- SpringMVC项目配置
一.创建一个maven项目 1.new一个maven项目,选择next,如图:
- laravel request 增加字段
https://segmentfault.com/q/1010000006898668 $input = $request->only(['username', 'password']); // ...
- vue下载文件
import fileDownload from 'js-file-download' let params = { ", ", "filename":&quo ...
- qemu-nbd方式挂载qcow2镜像
客户端配置 加载nbd模块 [root@centos sm]# rmmod nbd [root@centos sm]# modprobe nbd max_part=8 映射服务器的块设备到本地nbd设 ...
- 写写Web API基础
前两天突然心血来潮,对WEB Api 来了复习兴趣,虽然有很长时间没用了,现在有点迷湖.呀的!在VS2013的MVC项目(基于VS2012/MVC4的,如果是VS2013下的MVc5时,创建时勾上We ...
- 20145314郑凯杰 《Java程序设计》课程总结
20145314郑凯杰 <Java程序设计>课程总结 每周读书笔记链接汇总 ①寒假预习--"helloworld" ②第一周读书笔记 ③第二周读书笔记 ④第三周读书笔记 ...