02SpringMvc_springmvc快速入门小案例(XML版本)

这篇文章中,我们要写一个入门案例,去整体了解整个SpringMVC。

先给出整个项目的结构图:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUAAAAFWCAIAAACXfdN7AAAgAElEQVR4nO2db3QT1533lRd9ty84h56TzYuettksSct5lsWF7FM9WUqSbk3a52yeJ90S3A0kTdNpKCl/3E1jB5xgCMRxoEzADg4EY8qfKI6VOBFWcMAFPxRiiAuGYHDQOrZjB9uybIz/ji2b+7wYaebeuXdGI1kazR39Pue+kGbuzFzJ8/G9M9L9yoUAAOAWV7obAABA4lgn8MWm0yVHt6/x+UqObr/YdNqy4wKAg7FI4ItNp9f4fIHGCqm7YY3P5675HBwGgJmTKoEvefOVghDyHG9BI23XLpeead1ac2VPTmnl43meFB3aiIDodrnFQBqOnEz8giUvwi+4BH/kcUB0u1wu9Xn6OFtbUNyKEAp6PAUrG4Ppbg5BZ2NJdm2zpYdMicBNVfnk07w1Pl/VF1cPntp3yP9I+b4fryrYn7N6JgL7BVeE+E6pBAWWT196Q7/AXBwXfoF6Fcqr09m15QIHRHfMN7q1Mru0ILu08qx8Hpcy7DpbW5BdWuIZYO9A3kopxa3sakkWuLVSbnOEgfqVeAs1T2PBucClha+VFr5WWlg02Vs+2Vs+1vZm6NLrnfUFX3y0bo3P91B9R87hmoLfPvz86rWPrf5g3frtiR7HL6hnfEB0W9ArBES3y+12a6yJ9EqJuxQQ3S6XWxAIO7D/MfgLxbFcYDMHbK1Uzt3OxpJsT8lKT30nXmGgfmVpLIFNnP1RgZNFczHWJO2/ntbKbM2rMIQHgU+ePFlUVMRc9dr67VveaEC3/h9dLjadfqL83MM7rjy9rmrp0weXPr058WvggKg1KeUERLdLEDXdUEB0u0Vx5i6R3RvxTKfn40Hg2nqPhzCts7FkZWN9se0EJnrys7UFxbXEC4mrk7e9wHV1dXPnzp0zZ45ehdx1u1Cfj1EQuth0envBO79+Zs+GXFHXXlPjImbHJJ/r9NAaW+4WA6oR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HjImGBASBlcC9w/YcvjEphpcg98Bqf76H6jpzDNQW/ffj51WsfW/3BuvW6EwPNAgID9oN7gevezx8aDWvKiboPHz/414d3XHl6XdXSpw8ufXrz3t2vMTYm4mncoqgJnULafA11hTb1ihVqRR+FnmgYIysLAIzhXuDaqvWDo2G8zL578ey7FweuXch9fc9/Prfzd7niW29uZm9MCIw7pUZRYVPzXayp9pr/AQFGR00EY7HS7AyzsgDAAO4Frql8qX9oEi+ywKY2puyLLqXS6RA5kZ6ReqWsoMbZmn8TRAUzUTsAoAv3Ale/UxgcnMCLInDsaKuEBWZfDMcUWH2OD71BYCBhuBf4vUNbbgxM4EUROHa0lbHAxIg2ILrxITSdekWFWimPsCG06NccWCcrCwDMwb3ARw682hWa6ApNzL57sSLwM2tfVSoYRVvFEJi8VyVqrnyJ206MUCtaYHx/2F0tRlYWAJiDe4EP7i/uCEodQUnueOVyqOq4vNYW0VZG42IYMwMzgnuB97+9va1XauuVDlUdV+xt65XS3S4Vwy9igcDAjOBe4L17dvx39zhd5LVpjraKjJgNDAWBgRnBvcBlZW8wS7rbBQBWwL3AAJDJgMAAwDEgMABwDAgMABzz/wEkUF/NwETJ7wAAAABJRU5ErkJggg==" alt="" />

第一步:创建springmvc-day01这么一个web应用

第二步:导入springioc,springweb , springmvc相关的jar包

第三步:在/WEB-INF/下创建web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>SpringMvc_10day_self</display-name>
<servlet>
<!--这个名字可以随便取得,但是这个名字取了之后,以后在 WEB-INF下面创建SpirngMVC的配置文件是,命名必须以这个开头, 所以这里取名叫做DispatcherServlet,那么之后的xml文件取名必须为DispatcherServlet-servlet.xml(一个字都不能差) -->
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class> org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>*.action</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list>
</web-app>

第四步:创建HelloAction控制器类:

/**
* Create by 沈晓权
* Create on 2016年8月6日下午2:01:49
*/
package com.guigu.shen.Action; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller; public class HelloAction implements Controller { @Override
public ModelAndView handleRequest(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
ModelAndView modelAndView=new ModelAndView();
modelAndView.addObject("message","这是我得第一个"
+ "SpringMvc应用程序");
modelAndView.setViewName("/jsp/success.jsp");
return modelAndView; } }

第五步:在/WebRoot/下创建jsp/success.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>My JSP 'index.jsp' starting page</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>
Success. <br>
${message}
</body>
</html>

第六步:在/WEB-INF/创建DispatcherServlet-servlet.xml配置文件,xml头部信息与spring.xml相同

注意:该配置文件的命名规则:web.xml文件中配置的<servlet-name>的值-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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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 http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"
>
<!-- 控制器(程序员) -->
<bean name="/hello.action" class="com.guigu.shen.Action.HelloAction"></bean> <!-- 映射器(框架)
BeanNameUrlhanderMapping的作用是将上面那个bean标签的name属性当做URL请求,
这个映射器配不配都可以,就算不配,系统也会自己去创建的
-->
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean> <!-- 适配器(框架)
SimpleControllerHandlerAdapter的作用是查找实现了Colltroler接口的Action类

  这个适配器配不配都可以,就算不配,系统也会自己去创建的
-->
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"></bean> <!-- 视图解析器(框架)
InternalResourceViewResolver的作用是通过ModelAndView对象中封装的视图名找到真正的jsp页面路径。比如说
modelAndView.setViewName("/jsp/success.jsp")这里只是封装了一个"/jsp/success.jsp"这么一个字符串,就由InternalResourceViewResolver
去把他解析成真正的路径。

这个适配器配不配都可以,就算不配,系统也会自己去创建。
--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"></bean>
</beans>

最后一步:

在地址栏输入:http://127.0.0.1:8080/SpringMvc_10day_self/hello.action

运行结果如下:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdIAAABcCAIAAABVz6N9AAAHjUlEQVR4nO3dy5mzSAyGUTIiIgIilVkRwOQwG/LxLLhJVZIoDNZvz7zn6UU3xkBj+BBFGbq//v6HH3744YeftJ/uBQBIROwCQCpiFwB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4EItzn/Cp+MXX1937h4ByAVsfsVPlztBp2kAWQjdgEgFbELAKmIXQBIRewCQCpiFwBSEbsAkIrYBYBUxC4ApCJ2ASAVsQsAqYhdAEhF7AJAKmIXAFIRuwCQitgFgFTELgCkInYBIBWxCwCpiF0ASEXsAkAqYhcAUhG7AJCK2AWAVMQuAKQidgEgFbELAKmIXQBIRewCQCpiFwBSEbsAkIrYBYBUxC4ApCJ2ASAVsQsAqYhdAEhF7AJAKmIXAFIRuwCQitgFgFTELgCk+hdie3DIHiFf0gAAAABJRU5ErkJggg==" alt="" />

以上就是一个入门小案例。

思考一些问题:SpringMVC创建的Action是单例模式呢还是什么?

验证一下:

修改代码如下:

/**
* Create by 沈晓权
* Create on 2016年8月6日下午2:01:49
*/
package com.guigu.shen.Action; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller; /*
* Create by 沈晓权
* Create on 2016年8月6日下午2:01:49
*/
public class HelloAction implements Controller {
/**
*
*/
public HelloAction() { System.out.print("创建了一个Action");
}
@Override
public ModelAndView handleRequest(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
System.out.println("this is HelloAction handleRequest");
ModelAndView modelAndView=new ModelAndView();
modelAndView.addObject("message","这是我得第一个"
+ "SpringMvc应用程序");
modelAndView.setViewName("/jsp/success.jsp");
return modelAndView; } }

运行结果为:

创建了一个Action    2016-8-6 15:25:22 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler

信息: FrameworkServlet 'DispatcherServlet': initialization completed in 523 ms
this is HelloAction handleRequest
this is HelloAction handleRequest
this is HelloAction handleRequest

运行结果表明这就是一个单例模式。

构造器只会走一次,就是只创建一个对象,但是public ModelAndView handleRequest(HttpServletRequest arg0,HttpServletResponse arg1)这个方法就会执行n多次。

上一篇:(转)颜色渐变CSS


下一篇:C++基础--类与对象(中)--构造函数,析构函数,拷贝构造