SpringMVC(2)

spring的配置文件

 web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.4" 

xmlns="http://java.sun.com/xml/ns/j2ee" 

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 

http://java.sun.com/xml/ns/j2ee/web-app_2_4.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>

  <welcome-file-list>

    <welcome-file>index.jsp</welcome-file>

  </welcome-file-list>

</web-app>

设置的为DispatcherServlet继承FrameworkServlet 

FrameworkServlet 继承HttpServletBean

HttpServletBean继承httpServlet

springMVCsevlet的配置文件

文件名必须是web.xml配置的servlet的名字-servlet.xml

<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean>

<bean name="/welcom.htm" class="com.web.WelcomControl"></bean>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

  <property name="prefix" value="/WEB-INF/jsp/"/>

  <property name="suffix" value=".jsp"/>

</bean>

SpringMVC默认的Control是BeanNameUrlHandlerMapping以上配置可不用配置

InternalResourceViewResolver配置返回的视图。

prefix+view+suffix  如:/WEB-INF/jsp/welcom.jsp

WelcomControl控制层原始的是继承AbstractController

public class WelcomControl extends AbstractController {

protected ModelAndView handleRequestInternal(HttpServletRequest request,

HttpServletResponse response) throws Exception {

          System.out.println("我已经访问到了。。。。");

return new ModelAndView("welcom");

}

}

相关推荐