SpringMVC基础
学习MVC的步骤
1.搭建环境
2.如何完成Controller和viewer的映射
3.如何把值传递给Controller
4.Controller如何把值传递给viewer
5.异常处理
6.页面标签
7.文件上传
8.深入源代码
1.搭建SpringMVC环境
创建一个动态的JAVA项目, 导入SpringMVC的jar包和apache的commons-logging 包
2.配置 web.xml文件
创建一个hello servlet,所有请求都通过这个hello servlet来处理
<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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"> <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>
</web-app>
3.创建hello-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:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 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"> <context:component-scan base-package="zttc.itat.controller"/> <mvc:annotation-driven/> <!-- 将静态文件指定到某个特殊的文件夹中统一处理 --> <mvc:resources location="/resources/" mapping="/resources/**"/> <bean name="/welcome.html" class="zttc.itat.controller.WelcomeController"></bean> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> </beans>
posted on 2017-07-13 22:31 dawangandy 阅读(172) 评论(0) 收藏 举报
浙公网安备 33010602011771号