目标:使用SpringMvc框架,开发HelloWorld项目
步骤:
1.准备SpringMvc相关jar包
commons-io-1.2.jar
commons-logging-1.1.1.jar
freemarker.jar
hibernate-validator-4.0.2.GA.jar
jstl-1.2.jar
log4j-1.2.14.jar
org.springframework.context.support-3.1.0.M2.jar
servlet-2.3.jar
slf4j-api-1.5.6.jar
slf4j-log4j12-1.5.6.jar
spring-asm-3.0.3.RELEASE.jar
spring-beans-3.0.3.RELEASE.jar
spring-context-3.0.3.RELEASE.jar
spring-core-3.0.3.RELEASE.jar
spring-expression-3.0.3.RELEASE.jar
spring-web-3.0.3.RELEASE.jar
spring-webmvc-3.0.3.RELEASE.jar
validation-api-1.0.0.GA.jar
commons-fileupload-1.1.1.jar
2.创建Dynamic Web Project项目,名称为helloworld,将SpringMvc相关jar包复制到WEB-INF/lib文件夹下
3.配置SpringMvc相关文件
①web.xml:
②在WEB-INF文件夹下新建dispatcher-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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
"> <!-- 搜索的控制类路径(C) --> <context:component-scan base-package="com.myapps.controllers" /> <!-- 配置视图路径(V) --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/"/> <property name="suffix" value=".jsp"/> </bean></beans>
③新建包:com.myapps.controllers
④在上面的包内新建类:HelloWorldController.java
⑤在WEB-INF文件夹下新建views文件夹,在views文件夹内新建helloworldPage.jsp
⑥接着在WebContent下新建index.htm(注意后缀是htm,因为如果是html的话,会和web.xml的<url-pattern>*.html</url-pattern>拦截的后缀名冲突,当然也可以新建index.jsp文件)
⑦最后,部署项目,然后启动tomcat服务器,输入http://localhost:8080/helloworld/index.htm ,点击链接进行测试。这样简单的Hello,world入门就完成了。
如果需要jar包,请发邮件到:357228560@qq.com 索取