您的位置:首页 > 编程语言 > Java开发

Spring-MVC框架下对web.xml文件及spring_mvc.xml文件内容的释义资料整理

2017-03-01 23:22 621 查看
初学Spring,对各种配置语句的作用知之甚少,有幸浏览诸位技术大牛的分享,让我获益良多,特将所搜集资料汇总,供大家参考,共同进步。

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name>Archetype Created Web Application</display-name>
<
4000
context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml,classpath:spring_validate.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>SpringMVC4</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring_mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringMVC4</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>


1.web.xml中< context-param> < /context-param>,< listener>< /listener>的作用过程

转自http://blog.csdn.net/jubincn/article/details/9115205

2..web.xml中< filter>< /filter>,< filter-mapping>< /filter-mapping>的作用过程

转自http://www.cnblogs.com/wjqblogs/p/4226655.html?utm_source=tuicool&utm_medium=referral

3.web.xml中< servlet>< /servlet>< servlet-mapping>< /servlet-mapping>

< servlet-name> 这个是我们要注册servlet的名字,一般跟Servlet类名有关

< servlet-class> 这个就是指向我们要注册的servlet 的类地址, 要带包路径以上两个包在一个servlet 节点之下.

< servlet-mapping> 是用来配置我们注册的组件的访问路径,里面包括两个节点一个是 < servlet-name> 这个要与 前面写的servlet一致另一个是 < url-pattern> 配置这个组件的访问路径

转自http://blog.csdn.net/hello5orld/article/details/9407905

4.< url-pattern>匹配规则

转自http://www.cnblogs.com/canger/p/6084846.html

转自http://blog.csdn.net/u012679583/article/details/52816257

spring_mvc.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" xmlns:p="http://www.springframework.org/schema/p"
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-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
">
<context:component-scan base-package="com.li.controller"></context:component-scan>
<mvc:annotation-driven/>

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


1.< context:component-scan base-package=”“>< /context:component-scan>的作用过程以及< mvc:annotation-driven/>必不可少的原因

转自http://blog.csdn.net/jbgtwang/article/details/7359592

转自http://blog.csdn.net/lf_software_studio/article/details/8256510

spring.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" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

<mvc:default-servlet-handler/>

</beans>


1.Spring-MVC处理静态资源的方式

转自http://www.cnblogs.com/fangqi/archive/2012/10/28/2743108.html

转自http://blog.csdn.net/qq_16465949/article/details/51907503
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring web.xml