java——springmvc——注册中央调度器

在WEB-INF下的web.xml中配置

xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    

    
    <servlet>
        <servlet-name>springmvcservlet-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>springmvcservlet-name>
        
        <url-pattern>*.dourl-pattern>
    servlet-mapping>

web-app>

 

springmvc的核心对象是:DispatcherServlet

springmvc最基本的依赖是:

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

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0modelVersion>

  <groupId>com.bjpowernodegroupId>
  <artifactId>ch01-primaryartifactId>
  <version>1.0-SNAPSHOTversion>
  <packaging>warpackaging>

  <name>ch01-primary Maven Webappname>
  
  <url>http://www.example.comurl>

  <properties>
    <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
    <maven.compiler.source>1.8maven.compiler.source>
    <maven.compiler.target>1.8maven.compiler.target>
  properties>

  <dependencies>
      <dependency>
          <groupId>javax.servletgroupId>
          <artifactId>javax.servlet-apiartifactId>
          <version>3.1.0version>
      dependency>
      
      <dependency>
          <groupId>org.springframeworkgroupId>
          <artifactId>spring-webmvcartifactId>
          <version>4.3.16.RELEASEversion>
      dependency>
  dependencies>

  <build>
      <plugins>
          <plugin>
              <artifactId>maven-compiler-pluginartifactId>
              <version>3.1version>
              <configuration>
                  <source>1.8source>
                  <target>1.8target>
              configuration>
          plugin>
      plugins>
  build>
project>

 在resources文件夹下配置springmvc.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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    
    
    <bean id="/some.do" class="com.bjpowernode.controller.MyController" />

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

 

转载于:https://www.cnblogs.com/Tpf386/p/11184609.html

你可能感兴趣的:(java,测试,前端)