Spring MVC 配置
来源:互联网 发布:京东java面试题 编辑:程序博客网 时间:2024/05/16 12:44
web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"><servlet><servlet-name>spring</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>spring</servlet-name><url-pattern>/</url-pattern></servlet-mapping></web-app>
spring-servlet.xml
<?xml version="1.0" encoding="UTF-8"?><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"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd "><!-- mvc的注解驱动 --><mvc:annotation-driven/><!-- 一旦有扫描器的定义mvc:annotation-driven不需要,扫描器已经有了注解驱动的功能 --><context:component-scan base-package="com.raven.controller"/><!-- 前缀+ viewName +后缀 --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!-- webroot到某一指定的文件夹的路径 --><property name="prefix" value="/WEB-INF/jsp/"></property><!-- 视图名称的后缀 --><property name="suffix" value=".jsp"></property></bean><mvc:interceptors><mvc:interceptor><mvc:mapping path="/**"/><bean class="com.raven.interception.GInterception"></bean></mvc:interceptor></mvc:interceptors></beans>
hello.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>哈哈哈哈哈哈哈</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> </head> <body> HELLO WORLD </body></html>
配置Controller
HelloController.javapackage com.raven.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import com.raven.model.Person;@Controllerpublic class HelloController {@RequestMapping("/hello1")public String hello1(Person person){System.out.println("---------------------------------");System.out.println(person.getName());System.out.println(person.getAge());System.out.println("---------------------------------");return "hello";}}
配置拦截器
GInterception.java
</pre><pre name="code" class="java">package com.raven.interception;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.web.servlet.HandlerInterceptor;import org.springframework.web.servlet.ModelAndView;public class GInterception implements HandlerInterceptor {@Overridepublic void afterCompletion(HttpServletRequest arg0,HttpServletResponse arg1, Object arg2, Exception arg3)throws Exception {// TODO Auto-generated method stub}@Overridepublic void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,Object arg2, ModelAndView arg3) throws Exception {System.out.println("after");}@Overridepublic boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1,Object arg2) throws Exception {System.out.println("before");return true;}}
JavaBean
Person.java
package com.raven.model;public class Person {private String name;private String age;public String getName() {return name;}public void setName(String name) {this.name = name;}public String getAge() {return age;}public void setAge(String age) {this.age = age;}}
0 0
- 【spring mvc】spring-mvc配置
- Spring MVC 配置
- Spring MVC 配置--解剖
- spring web mvc配置
- Spring MVC 相关配置
- Spring MVC 配置
- Spring MVC国际化配置
- Spring MVC 配置--解剖
- Spring MVC 配置
- Spring MVC配置(一)
- Spring MVC配置(二)
- Spring MVC配置(三)
- Spring MVC配置(四)
- Spring MVC国际化配置
- spring mvc 基本配置
- Spring MVC配置
- spring mvc注解配置
- Spring MVC配置
- 第九周上机实践项目2——Time类中的运算符重载(续)
- MySQL学习笔记_9_MySQL高级操作(上)
- IOS KVC的详细使用
- IOS开发基础—关于uikit框架里面uiview类的一些知识点
- CTP固件升级接口技术规范3.0
- Spring MVC 配置
- 补间动画
- 关于卷积
- Android Service学习之AIDL, Parcelable和远程服务
- VMware10.01永久序列号
- spring @Transactional 配置事务 注意事项
- 全栈工程师
- jQuery.FormValidator表单验证需要注意的问题
- Android sharedUserId研究记录