springmvc20170322
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name></display-name> <!-- 配置 springmvc的核心控制器
这里的 <servlet-name>springmvc</servlet-name>
springmvc就是规定了 我们springmvc的配置文件的名称
<servlet-name>-servlet.xml
-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet> <servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
<!-- 为什么不能配置/*
我们打开浏览器 第一次访问 项目名/hello ,会通过我们的handlerMaping找 有没有bean name="/hello"!
有就进入对应的controller进行操作,之后根据controller中返回的ModelAndView ===》hello01!
让试图解析器进行解析 :解析之后 变成了/SpringMVC001/WEB-INF/jsp/hello01.jsp 如果我们配置的是 /* 那么解析之后的路径也会被当成一个Bean name来处理,很显然我们没有这个bean,所以会报错! /: 只会匹配 /login /index 不能匹配 /*.jsp 这样的后缀url
/*:匹配所有的请求 所以我们hello01.jsp 也会被拦截
-->
</servlet-mapping> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- 采用默认的方式 BeanNameUrlHandlerMapping -->
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/> <!-- name="/hello" 用户的请求 class就是我们的Controller处理器-->
<bean name="/hello01" class="cn.rick.controller.HelloController"/> <!-- 视图解析器 项目名/web-inf/jsp/springmvc.jsp 需要设置前缀 和后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/> </bean> </beans>
springmvc-servlet.xml
package cn.rick.controller; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController; public class HelloController extends AbstractController { // 第一个springmvc小例子
/**
* handleRequestInternal():对应struts2的 execute()
* ModelAndView:返回值 需要核心配置文件中的试图解析器 解析
*/
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {
System.out.println("第一个springmvc小例子....");
// hello01就是我们返回的视图名称 但是 现在只是一个字符串
return new ModelAndView("hello01");
} }
HelloController.java
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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>Insert title here</title>
</head>
<body>
成功
</body>
</html>
hello01.jsp
springmvc20170322的更多相关文章
随机推荐
- treetable adding nodes at root level
describe("loadBranch()", function() { beforeEach(function() { this.newRows = " ...
- Mybatis与Spring整合方法
实现mybatis与spring进行整合,通过spring管理SqlSessionFactory.mapper接口. tips:mybatis官方提供与mybatis与spring整合jar包. 一. ...
- Pycharm 专业版安装
1.Pycharm官网,网址:http://www.jetbrains.com/pycharm/download/#section=windows,下载PyCharm安装包,根据自己电脑的操作系统进行 ...
- 03C++基本数据类型
基本数据类型 2.2.1整型数据 短整型(short int) 有符号短整型(signed short int) 无符号短整型(unsigned short int) 一般整型(int) 有符号一般整 ...
- boostrap标签
字体: <lead>:加强显示 <strong><b>:字体加粗 <i><em>:斜体字 .text-muted:提示,使用浅灰色(#999 ...
- extjs动态插入一列
StdDayWordQuery:function(btn,event){ var form=Ext.getCmp('queryFormSDW'); var userNameORuserCode = f ...
- 折线分割平面(hdoj 2050,动态规划递推)
Problem Description 我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目.比如,一条折线可以将平面分成两部分,两条折线最多可以将平面 ...
- Linux 源码
https://elixir.bootlin.com/linux/latest/source
- linux ifstat-统计网络接口流量状态
推荐:更多linux 性能监测与优化 关注:linux命令大全 ifstat命令就像iostat/vmstat描述其它的系统状况一样,是一个统计网络接口活动状态的工具.ifstat工具系统中并不默认安 ...
- 正确的在循环list的时候删除list里面的元素
s = [1,2,3,4,5] for i in s: s.remove(i) print(s) 输出结果:[2, 4] 1.当第一次删除后,后面的元素会前移,此时s=[2,3,4,5], 2.然 ...