标签:pat override xtend throw sim cat 1.4 lan protected
1.AbstractController
若处理器继承自AbstractController类,那么该控制器就具有了一些新功能。因为AbstractControll类还继承自一个父类WebContentGenerator,WebContentGenerator具有supportMethods属性,可以设置支持的HTTP数据提交方式。默认支持GET/POST/HEAD.
1.1:中央调度器
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Archetype Created Web Application</display-name> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
1.2:定义处理器
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.AbstractController; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class MyAbstractController extends AbstractController { @Override protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { return new ModelAndView("index"); } }
1.3:jsp页面搭建
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <body> <h2>Spring第一个Spring MVC程序</h2> <img src="images/1504837384314376.png">/ </body> </html>
1.4:spring-mvc.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: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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!--处理器映射器--> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="urlMap"> <map> <entry key="/*.do" value="firstController"></entry> </map> </property> </bean> <!--拦截请求的方式--> <bean id="firstController" class="cn.happy.controller.MyAbstractController"> <property name="supportedMethods" value="POST,GET"></property> </bean> <!--视图解析器--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/"/> <property name="suffix" value=".jsp"/> </bean> <!--拦截静态文件--> <mvc:default-servlet-handler/> </beans>
测试结果:
Spring02 AbstractController And MultiActionController
标签:pat override xtend throw sim cat 1.4 lan protected
原文地址:http://www.cnblogs.com/Chenghao-He/p/7747047.html