java springmvc注册中央调度器代码解析

  

这篇文章主要介绍了java springmvc注册中央调度器代码解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

  

在- inf下的web . xml中配置

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; web 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 "比;   & lt; !——注册springmvc框架的核心对象DispatcherServlet(中央调度器)——比;      & lt; !   在服务器启动的时候,会找/web - inf/myweb-servlet。xml/web - inf/springmvc-servlet.xml   找的文件命名是:目录是- inf,文件名称是:& lt; servlet-name> -servlet.xml      为什么要找这个文件吗?   在DispatcherServlet这个Servlet的init()方法中,会创建springmvc的容器对象WebApplicationContext,   在创建容器对象时,会加载读取springmvc需要的配置文件,默认查找位置就是/web - inf/& lt; servlet-name> -servlet.xml   springmvc需要的配置文件,可以单独指定的,需要配置参数contextConfigLocation。      ——比;   & lt; servlet>   & lt; servlet-name> springmvc   & lt; !——前端控制器(前端控制器)——比;   & lt; servlet-class> org.springframework.web.servlet.DispatcherServlet      & lt; !——指定springmvc配置文件——比;   & lt; init-param>   & lt; param-name> contextConfigLocation   & lt; param-value>类路径:springmvc.xml   & lt;/init-param>   & lt; !——在服务器启动的时候,创建Servlet对象——比;   & lt; load-on-startup> 1 & lt;/load-on-startup>   & lt;/servlet>      & lt; servlet-mapping>   & lt; servlet-name> springmvc   & lt; !   & lt; url-pattern>:表示把请求交给指定的Servlet对象。只有把请求交给DispatcherServlet,   这样的请求才能使用springmvc框架处理。使用DispatcherServlet接收用户的请求。   在框架中url模式:   1.扩展名:*。xxxx, xxxx就是自定义的扩展名,例如*。* .action, * .mvc等等,不能使用* . jsp   2 .使用斜杠“/?   ——比;   & lt; url-pattern> * .do   & lt;/servlet-mapping>   & lt;/web-app>      

springmvc的核心对象是:DispatcherServlet

  

springmvc最基本的依赖是:

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;      & lt;项目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”比;   & lt; modelVersion> 4.0.0      & lt; groupId> com.bjpowernode   & lt; artifactId> ch01-primary   & lt; version> 1.0 -snapshot   & lt; packaging> war      & lt; name> ch01-primary Maven Webapp   & lt; !——FIXME改变项目的网站比;   & lt; url> http://www.example.com</url>      & lt; properties>   & lt; project.build.sourceEncoding> UTF-8   & lt; maven.compiler.source> 1.8 & lt;/maven.compiler.source>   & lt; maven.compiler.target> 1.8 & lt;/maven.compiler.target>   & lt;/properties>      & lt; dependencies>   & lt; dependency>   & lt; groupId> javax.servlet   & lt; artifactId> javax.servlet-api   & lt; version> 3.1.0   & lt;/dependency>   & lt; !——springmvc的依赖——比;   & lt; dependency>   & lt; groupId> org.springframework   & lt; artifactId> spring-webmvc   & lt; version> 4.3.16.RELEASE   & lt;/dependency>   & lt;/dependencies>      & lt; build>   & lt; plugins>   & lt; plugin>   & lt; artifactId> maven-compiler-plugin   & lt; version> 3.1 & lt;/version>   & lt; configuration>   & lt; source> 1.8 & lt;/source>   & lt; target> 1.8 & lt;/target>   & lt;/configuration>   & lt;/plugin>   & lt;/plugins>   & lt;/build>   & lt;/project>      

在资源文件夹下配置springmvc.xml文件

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt;豆类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”比;      & lt; !——springmvc的配置文件:声明的网络相关的对象,例如处理器对象,视图对象等——比;   & lt; !——声明处理器对象,让容器创建处理器对象,并把请求交给这个对象   类:处理器类的全限定名称   id:请求的uri地址,需要以“/笨耐贰?   ——比;   & lt; bean id="/一些。做“阶级=" com.bjpowernode.controller。MyController”/比;      & lt; !——声明视图解析器:springmvc中的一个对象,处理视图的。能指定视图的路径和扩展名   InternalResourceViewResolver:内部资源视图解析器,处理jsp、jstl等视图文件   ——比;   & lt; bean类=皁rg.springframework.web.servlet.view.InternalResourceViewResolver”比;   & lt; !——指定前缀:视图文件目录——比;   & lt;属性名="前缀" value=" https://www.yisu.com/WEB-INF/view/"/比;   & lt; !——指定后缀:视图文件的扩展名——比;   & lt;属性名="后缀" value=" https://www.yisu.com/zixun/.jsp "/比;   & lt;/bean>   & lt;/beans>

java springmvc注册中央调度器代码解析