准备工具:
eclipse-jee-mars-2-win32-x86_64
apache-tomcat-6.0.48
SpringMVC需要的jar包
SpringMVC简介
1、SpringMVC和Struts一样是一个MVC框架,和Spring无缝连接。和Struts2有点相似。
2、SpringMVC属于SpringFrameWork的后续产品,Spring框架提供了构建Web应用程序的全功能MVC模块。
3、使用Spring可插入的MVC架构,可以选择是使用的内置的Spring web框架还可以是Struts这样的Web框架。
新建一个SpringMVC项目
1、file-->new-->Dynamic Web Project-->SpringMVC1
2、选择Apache Tomcat v6.0,配置好服务。

3、Finish
4、生成一个SpringMVC1 Project

5、添加 lib

6、web.xml 配置
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

7、control类:HelloWorldController.java
package com.tiany.web.controller;
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 HelloWorldController implements Controller {
@Override
public ModelAndView handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
System.out.println("----hello SpringMVC------");
// TODO Auto-generated method stub
return new ModelAndView("/welcome");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}

8、spring-servlet.xml 配置
<?xml version="1.0" encoding="UTF-8"?>
<!-- Bean头部 -->
<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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
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
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<bean name="/test1/helloworld" class="com.tiany.web.controller.HelloWorldController"></bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>-->
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>

详细解析:http://www.cnblogs.com/yw0219/p/6086571.html
9、apache 配置


启动后报错:

重命名下名称
springMVC-servlet.xml

查看页面
http://localhost:8080/SpringMVC1/test1/helloworld

千里之行始于足下,just hello world!
网友评论