工具:myEclipse使用这个软件可以直接把spring需要的包直接导入到lib目录里面
添加spring包:spring 3.1 core、spring 3.1 web、spring web flow2.3 core、spring web flow 2.3 jsf 外加:
1、添加spring框架的时候无需使用本身自己的application.xml ,因为这个要自己创建的才是合适自己的。
2、创建 xxx-servlet.XML
Create->other->Spring->Spring bean Definition
选上:beans、context、mvc 即可
<?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: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-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<context:component-scan base-package="lp" />
<mvc:annotation-driven />
<bean name="/welcome.html" class="lp.WelcomeCotroller"></bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
3、web.xml 配置(含中文过滤器及spring.xml拦截)
<?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">
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>CharacterFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
4、Controller也就是Ation
package lp;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class helloController {
@RequestMapping({"/hello","/"})
public String hello(){
System.out.println("hello");
return "hello";
}
}
通过这个就可以返回到hello.jsp中去了、Spring 依赖于注入的方式,上面的@XXX 就是为注入标识
这样就可以搭建了一个简单的请求跳转的mvc