`
zhangyang5023637
  • 浏览: 326 次
社区版块
存档分类
最新评论

Spring MVC 配置

阅读更多
Spring MVC 模式:
   
    Spring MVC模式下,把其它的一些组件当作一个个的bean对象来处理,Spring 充当一个对象工厂的作用。
    Spring MVC 搭建方法-->
    1:  导入Spring 开发的Jar 和相关的依赖包
    2: 在 web.xml 文件中,配置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"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee      
                http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        version="3.0">

<servlet>
<servlet-name>SSHOver</servlet-name>
                <servlet- class>
                    org.springframework.web.servlet.DispatcherServlet
                </servlet-class>
     <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SSHOver</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

    </web-app>

    3: 编写 控制器测试文件
        在 src目录下 新建一个 控制器文件
    4:  在 WEB-INF 目录下 编写一个 Spring.xml 文件,用来处理 将请求分派出去,映射相关的Action 请求。
     <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"      xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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.xsd 
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx.xsd
      http://www.springframework.org/schema/task
      http://www.springframework.org/schema/task/spring-task-3.2.xsd
      http://www.springframework.org/schema/mvc 
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="start.do">startController</prop>
</props>
</property>
</bean>
<bean id="startController" class="com.test.StartController"></bean>

</beans>
    5: 编译测试 运行项目。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics