Objective
For a project, there are usually several types of XML files that need to be written.
- Xml
- Spring-context.xml
- Spring-mvc.xml
- Other.xml
- ...
regardless of the number of configuration files, it is certain that these configuration files are specified in Web. Xml.
follow-up slowly elaborated.
Xml
Web . XML can be understood as a portal to a Java project. There are usually several types of nodes in Web. Xml that are listed in the Order of loading .
Listener
This is the listener, in the above 3 is the back chord loading, indicating whether to listen to an action or not, what happens after the action.
monitoring-is the setting, modification, and substitution of related values in a certain range (application,session,request), which trigger events, and the agent mechanism of events in Java, event handling is the use of the listener mechanism, So in order to be able to take the corresponding measures when the event is triggered, it is necessary to----> inherit such listener, overwrite the corresponding method in the listener, overwrite the corresponding event processing method, and deal with the corresponding event in the corresponding method, that is, listening
Reference link: wirelessly listener mode
in the Java Web, there are typically 3 listener objects:
- ServletContext (Spring in relation to the ServletContext class is signed as follows:
Public class Contextloaderlistener extends Contextloader Implements Servletcontextlistener {..... }
Spring's listener needs to set Context-param to specify the path to the spring configuration file.
<!--1. Spring Auto Scan - <Listener> <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class> </Listener> <Context-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>Classpath*:spring/application-*.xml Classpath*:spring/webservice.xml</Param-value> </Context-param>
Filter
This is the filter, which is loaded for the second one. Any path that is specified will need to be filtered by this filter. The usual use of the filter is:
- Encoding Conversion Filter
- Secure processing of XSS, SQL injection interception filters
- Put filters created for support
- Data Connection Pool Druid filter
- 。。。
<Filter> <Filter-name>Encodingfilter</Filter-name> <Filter-class>Org.springframework.web.filter.CharacterEncodingFilter</Filter-class> <async-supported>True</async-supported> <Init-param> <Param-name>Encoding</Param-name> <Param-value>UTF-8</Param-value> </Init-param> <Init-param> <Param-name>Forceencoding</Param-name> <Param-value>True</Param-value> </Init-param> </Filter> <filter-mapping> <Filter-name>Encodingfilter</Filter-name> <Url-pattern>/*</Url-pattern> </filter-mapping>
Servlet
A servlet is the last loaded in three classes, usually as a control layer, and is managed in the SSM in SPRINGMVC.
<!--2. SPRINGMVC Configuration - <!--Spring MVC servlet - <servlet> <Servlet-name>Springmvc</Servlet-name> <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class> <Init-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>Classpath:spring/spring-mvc.xml</Param-value> </Init-param> <Load-on-startup>1</Load-on-startup> <async-supported>True</async-supported> </servlet> <servlet-mapping> <Servlet-name>Springmvc</Servlet-name> <!--This can be configured as *.do, which corresponds to struts ' suffix habits - <Url-pattern>/</Url-pattern> </servlet-mapping>
Interpretation of common elements in Web. xml