dorm---3、web.xml、springmvc.xml基础配置,随便用一个控制器测试springmvc配置

文章目录

  • 1、web.xml基本配置
  • 2、springmvc.xml基本配置
  • 3、用controller测试springmvc是否配置成功

1、web.xml基本配置


<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"
         >
  <display-name>Archetype Created Web Applicationdisplay-name>
  
    
  <servlet>
    <servlet-name>dispacherServletservlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
    <init-param>
      <param-name>contextConfigLocationparam-name>
      <param-value>classpath:springmvc.xmlparam-value>
    init-param>
    <load-on-startup>1load-on-startup>
  servlet>
  <servlet-mapping>
    <servlet-name>dispacherServletservlet-name>
    <url-pattern>*.dourl-pattern>
  servlet-mapping>

web-app>

2、springmvc.xml基本配置


<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:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.3.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd">
    
    <context:component-scan base-package="com.jmy.dorm.web.controller">context:component-scan>

    
    <mvc:annotation-driven>mvc:annotation-driven>
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>

    
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
    bean>
beans>

3、用controller测试springmvc是否配置成功

dorm---3、web.xml、springmvc.xml基础配置,随便用一个控制器测试springmvc配置_第1张图片
浏览器输入路径
dorm---3、web.xml、springmvc.xml基础配置,随便用一个控制器测试springmvc配置_第2张图片
出现测试的“dd”,表示测试成功
dorm---3、web.xml、springmvc.xml基础配置,随便用一个控制器测试springmvc配置_第3张图片

你可能感兴趣的:(配置xml文件)