Spring MVC3构建Web应用第二步
建立一个ant.properties文件,该文件会存放一些值的属性,并且这些值也会是ant.xml中用到的。请按如下步骤实现:
1)点文件—新建-文件
2) 将文件命名为ant.properties,并点完成,如下图:
3)打开ant.properties,修改tomcat.home的目录为你安装tomcat的实际目录。
1tomcat.home=C:/Tools/apache-tomcat-6.0.2
2tomcat.lib=${tomcat.home}/lib
2tomcat.lib=${tomcat.home}/lib
下载下面列表的.jar文件,并放到SampleSpringMVC/war/WEB-INF/lib下。
1commons-logging.jar
2jstl-api-1.2.jar
3jstl.jar
4org.springframework.asm-3.0.5.RELEASE.jar
5org.springframework.beans-3.0.5.RELEASE.jar
6org.springframework.context-3.0.5.RELEASE.jar
7org.springframework.core-3.0.5.RELEASE.jar
8org.springframework.expression-3.0.5.RELEASE.jar
9org.springframework.web-3.0.5.RELEASE.jar
10org.springframework.web.servlet-3.0.5.RELEASE.jar
11standard.jar
2jstl-api-1.2.jar
3jstl.jar
4org.springframework.asm-3.0.5.RELEASE.jar
5org.springframework.beans-3.0.5.RELEASE.jar
6org.springframework.context-3.0.5.RELEASE.jar
7org.springframework.core-3.0.5.RELEASE.jar
8org.springframework.expression-3.0.5.RELEASE.jar
9org.springframework.web-3.0.5.RELEASE.jar
10org.springframework.web.servlet-3.0.5.RELEASE.jar
11standard.jar
按如下修改web.xml:
1 <!-- Copyright : adobocode.com , 2010 -->
2
3<web-app id="WebApp_ID" version="2.4"
4 xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
6
7 <display-name>SampleSpringMVC</display-name>
8
9 <servlet>
10 <servlet-name>SampleSpringMVC</servlet-name>
11 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
12 <load-on-startup>1</load-on-startup>
13 </servlet>
14
15 <servlet-mapping>
16 <servlet-name>SampleSpringMVC</servlet-name>
17 <url-pattern>*.htm</url-pattern>
18 </servlet-mapping>
19
20 <welcome-file-list>
21 <welcome-file>index.jsp</welcome-file>
22 </welcome-file-list>
23
24</web-app>
2
3<web-app id="WebApp_ID" version="2.4"
4 xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
6
7 <display-name>SampleSpringMVC</display-name>
8
9 <servlet>
10 <servlet-name>SampleSpringMVC</servlet-name>
11 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
12 <load-on-startup>1</load-on-startup>
13 </servlet>
14
15 <servlet-mapping>
16 <servlet-name>SampleSpringMVC</servlet-name>
17 <url-pattern>*.htm</url-pattern>
18 </servlet-mapping>
19
20 <welcome-file-list>
21 <welcome-file>index.jsp</welcome-file>
22 </welcome-file-list>
23
24</web-app>
创建index.jsp,这个只需要在war/WEB-INF下建立即可,并且将内容设置为如下:
1<%@ page language="java" session="false" contentType="text/html; charset=UTF-8"%>
2<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
3<html>
4 <head>
5 <title>Adobocode : Sample Spring MVC</title>
6 </head>
7 <body>
8 <h2>Adobocode : Hello World</h2>
9 <br/>
10 <a href="<c:url value="personDisplay.htm"/>">Person List</a>
11 </body>
12</html>
2<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
3<html>
4 <head>
5 <title>Adobocode : Sample Spring MVC</title>
6 </head>
7 <body>
8 <h2>Adobocode : Hello World</h2>
9 <br/>
10 <a href="<c:url value="personDisplay.htm"/>">Person List</a>
11 </body>
12</html>