The Web. xml file is mainly configured as follows:
Configuration files that need to be loaded: Under the classpath, you can use a wildcard configuration similar to the following: Classpath:conf/spring/*/*.xml,
<context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:conf/spring/spring-da.xml, classpath:conf/spring/spring-res.xml, </param-value> </context-param>
Context-Loaded filtering:
<!--context Loader load Context-param-- <listener> <listener-class> org.springframework.web.context.contextloaderlistener</listener-class> </listener>
Excel templates are downloaded to prevent the case of compressed packets.
<!--Excel templates download- <mime-mapping> <extension>xlsx</extension> <mime-type >application/vnd.openxmlformats</mime-type> </mime-mapping>
Character filter: Prevent the Chinese garbled before and after the table, of course, it is best to ensure that the front page utf-8 background encoding is also utf-8
<!--character Filters-- <filter> <filter-name>CharacterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.characterencodingfilter</filter-class > <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>CharacterEncodingFilter</filter-name> <url-pattern>*</url-pattern> </filter-mapping>
SPring MVC's total Control distribution configuration:
<!--Spring MVC Master Controller Dispatcherservlet- <servlet> <servlet-name>pmp</servlet-name > <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class > <init-param> <param-name>contextConfigLocation</param-name> < param-value>classpath:conf/spring/spring-servlet.xml</param-value> </init-param> < load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> < servlet-name>pmp</servlet-name> <url-pattern>*.htm</url-pattern> < Url-pattern>*.action</url-pattern> </servlet-mapping>
Container Check Login control, and interception of requests:
<!--security Start--<security-constraint> <web-resource-collection> <web-res Ource-name>pmp-web-in</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>*& lt;/role-name> </auth-constraint> </security-constraint> <security-constraint> &L T;web-resource-collection> <web-resource-name>pmp-web-in</web-resource-name> <url- Pattern>/res/*</url-pattern> <url-pattern>/login.jsp</url-pattern> <url-patt Ern>/home/error.htm</url-pattern> </web-resource-collection> </security-constraint> <login-config> <auth-method>FORM</auth-method> <form-login-config> < ;form-login-page>/login.jsp</form-login-page> <form-error-page>/login.jsp</form-error-page> ; </form-login-config> </login-config> <security-role> <description>framework User Role </descriptioN> <role-name>*</role-name> </security-role> <!--security End--
Welcome page and Error Jump configuration:
<welcome-file-list> <welcome-file>redirect.jsp</welcome-file> </welcome-file-list > <error-page> <exception-type>java.lang.Throwable</exception-type> < location>/home/error.htm?errorcode=500</location> </error-page> <error-page> <error-code>500</error-code> <location>/home/error.htm?errorCode=500</location> </error-page> <error-page> <error-code>404</error-code> < location>/home/error.htm?errorcode=404</location> </error-page> <error-page> <error-code>403</error-code> <location>/home/error.htm?errorcode=403</location > </error-page>
The above is the basic configuration information of Web. XML in the project, which can be used to add and delete related configuration items according to their own project information.
The following is a related configuration of spring-servlet.xml file:
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf= "Http://cxf.apache.org/core"xmlns:p= "Http://cxf.apache.org/policy" xmlns:ss= "http://www.springframework.org/schema/security"Xmlns:jaxws= "Http://cxf.apache.org/jaxws" xmlns:jee= "Http://www.springframework.org/schema/jee"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:tx= "Http://www.springframework.org/schema/tx"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://Cxf.apache.org/corehttp://cxf.apache.org/schemas/core.xsdhttp//Cxf.apache.org/jaxwshttp://cxf.apache.org/schemas/jaxws.xsdhttp//Cxf.apache.org/policyhttp://cxf.apache.org/schemas/policy.xsdhttp//Www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsdhttp//Www.springframework.org/schema/jeehttp://www.springframework.org/schema/jee/spring-jee.xsdhttp//Cxf.apache.org/bindings/soaphttp://cxf.apache.org/schemas/configuration/soap.xsdhttp//www.springframework.org/schema/securityhttp://www.springframework.org/schema/security/spring-security.xsdhttp//WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOPhttp://www.springframework.org/schema/aop/spring-aop.xsdhttp//Www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp//Www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"><!--enable annotation scanning-<context:component-scan base- Package= "Com.lilin.pmp.web" use-default-filters= "false" > <context:include-filter type= "annotation" expression= " Org.springframework.stereotype.Controller "/> </context:component-scan> <!--enable spring MVC annotation Driver configuration-- <mvc:annotation-driven/> <!--Interceptor configuration-<mvc:interceptors> <mvc:interceptor> ; <mvc:mapping path= "/**/*.htm"/> <ref bean= "Loginuserinterceptor"/> </MVC:INTERCEPTOR&G T </mvc:interceptors> <!--===================== View Resovler =====================--<bean id= "view Resolver "Abstract= "true" > <property name= "Attributes" > <props> <prop key= "Resroot" >@{ resroot}</prop> <prop key= "Uaaresroot" >@{uaaResRoot}</prop> <prop key= " Envname ">@{envName}</prop> <prop key=" Minsuffix ">@{minSuffix}</prop> &L T;prop key= "appversion" >@{appVersion}</prop> <prop key= "Imghost" >@{imgHost}</prop> <prop key= "Imghosttag" >@{imgHostTag}</prop> <prop key= "Imghostnumber" >@{imgho stnumber}</prop> </props> </property> </bean> <bean id= "Jstlviewresolve Rclass= "Org.springframework.web.servlet.view.UrlBasedViewResolver"Parent= "Viewresolver" > <property name= "Order" value= "2"/> <property name= "Viewclass"value= "Org.springframework.web.servlet.view.JstlView"/> <property name= "prefix" value= "/web-inf/jsp/"/> <property name= "suffix" value= ". jsp"/> </bean> <bean id= "Freemarkerresolver"class= "Org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"Parent= "Viewresolver" > <!--<property name= "Cache" value= "true"/>--<property name= "order" Valu e= "1"/> <property name= "Viewnames" > <array> <value>*.ftl</value& Gt </array> </property> <!--<property name= "suffix" value= ". FTL"/>--<pro Perty name= "Requestcontextattribute" value= "request"/> <property name= "Exposespringmacrohelpers" value= "true "/> <property name=" exposerequestattributes "value=" true "/> <property name=" Exposesessionattri Butes "value=" true "/> <property name=" Allowsessionoverride "value=" true "/> <property name=" con Tenttype "value=" Text/html;charset=utf-8 "/><!--encode--<property name=" Viewclass "value= "Org.springframework.web.servlet.view.freemarker.FreeMarkerView"/> </bean> <!--==================== = View Resolver End ======================-<!--file Upload support-<bean id= "Multipartresolver"class= "Org.springframework.web.multipart.commons.CommonsMultipartResolver" > <property name= "defaultencoding" Value= "Utf-8" ></property> <property name= "Maxuploadsize" > <value>104857600</valu e><!--upload File size limit 100m,100*1024*1024--</property> <property name= "Maxinmemorysize" > <value>4096</value> </property> </bean> <bean id= "Webpropertyconfig"class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > <property name= "Locations" > <list> <value>classpath:conf/main-setting-web.properties</value> </ list> </property> <property name= "Placeholderprefix" value= "@{"/> <property name= " Systempropertiesmodename "value=" System_properties_mode_override "/> </bean> <bean id=" FreemarkerConfig "class= "Org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer" > <description>required forFreemarker to work in Web tier</description> <property name= "Configuration" ref= "Freemarkerconfiguration" /> </bean> <bean id= "Freemarkerconfiguration"class= "Org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean" > <description>Using The Config directly so we can use it outside the Web tier</description> <!--template Load path--<property name= "templateloaderpaths" > <LIST&G T <value>/WEB-INF/freemarker/</value> <value>/WEB-INF/uaa-freemarker/</value> <value>classpath:/</value> <value>/</value> </list> </property> <property name= "Configlocation" > <value>classpath:conf/freemarker.propert Ies</value> </property> <!--Global variables section--<property name= "Freemarkervariables" > <map> <entry key= "Xml_escape" value-ref= "fmxmlescape"/> <entry ke Y= "Html_escape" value-ref= "Fmhtmlescape"/> <entry key= "base" value= "@{base}"/> &L T;entry key= "Resroot" value= "@{resroot}"/> <entry key= "uaaresroot" value= "@{uaaresroot}"/> <entry key= "appversion" value= "@{appversion}"/> </map> </property> <pro Perty name= "defaultencoding" value= "Utf-8"/> </bean> <bean id= "Fmxmlescape"class= "Freemarker.template.utility.XmlEscape"/> <bean id= "Fmhtmlescape"class= "Freemarker.template.utility.HtmlEscape"/> <!--====================== i18n =============================== --<bean id= "Messagesource"class= "Org.springframework.context.support.ReloadableResourceBundleMessageSource" > <property name= "basename" Value= "Classpath:i18n/messages"/> </bean> <Beanclass= "Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" > <property name= " Messageconverters "> <list> <Beanclass= "Org.springframework.http.converter.StringHttpMessageConverter" > <property name= "Supportedmediat Ypes "> <list> <VALUE>TEXT/PLAIN;CHARSET=UTF-8</VALUE&G T </list> </property> </bean> </list> </prope Rty> </bean></beans>
Summary of Spring MVC project-related configuration files