SpringMvc web.xml配置实现原理过程解析

网友投稿 281 2022-11-27


SpringMvc web.xml配置实现原理过程解析

1、spring 框架解决字符串编码问题:过滤器 CharacterEncodingFilter(filter-name)

2、在web.xml配置监听器ContextLoaderListener(listener-class)

ContextLoaderListener的作用就是启动Web容器时,自动装配ApplicationContext的配置信息。因为它实现了ServletContextListener这个接口,在web.xml配置这个监听器,启动容器时,就会默认执行它实现的方法。

3、部署applicationContext的xml文件:contextConfigLocation(context-param下的param-name)

4、DispatcherServlet是前置控制器,配置在web.xml文件中的。拦截匹配的请求,Servlet拦截匹配规则要自已定义,把拦截下来的请求,依据某某规则分发到目标Controller(我们写的Action)来处理。

DispatcherServlet(servlet-name、servlet-class、init-param、param-name(contextConfigLocation)、param-value)

在DispatcherServlet的初始化过程中,框架会在web应用的 WEB-INF文件夹下寻找名为[servlet-name]-servlet.xml 的配置文件,生成文件中定义的bean

代码如下

xmlns:xsi="http://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">

characterEncodingFilter

org.springframework.web.filter.CharacterEncodingFilter

encoding

UTF-8

forceEncoding

true

characterEncodingFilter

/*

org.springframework.web.context.ContextLoaderListener

contextConfigLocation

classpath:spring/applicationContext.xml

default

*.css

default

*.swf

default

*.gif

default

*.jpg

default

*.png

default

*.js

default

*.html

default

*.xml

default

*.json

default

*.map

DispatcherServlet

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:spring/dispatcher-servlet.xml

1

DispatcherServlet

/

login.html

404

/nopage.html

java.lang.NullPointerException

/error.html

360

xmlns:xsi="http://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">

characterEncodingFilter

org.springframework.web.filter.CharacterEncodingFilter

encoding

UTF-8

forceEncoding

true

characterEncodingFilter

/*

org.springframework.web.context.ContextLoaderListener

contextConfigLocation

classpath:spring/applicationContext.xml

contextConfigLocation

classpath:spring/applicationContext.xml

default

*.css

default

*.swf

default

*.gif

default

*.jpg

default

*.png

default

*.js

default

*.html

default

*.xml

default

*.json

default

*.map

DispatcherServlet

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:spring/dispatcher-servlet.xml

1

DispatcherServlet

/

login.html

404

/nopage.html

java.lang.NullPointerException

/error.html

360


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:2020最新eclipse安装过程及细节
下一篇:SpringMvc响应数据及结果视图实现代码
相关文章

 发表评论

暂时没有评论,来抢沙发吧~