电商项目之理解web.xml、spring.xml、springmvc.xml(SSM超级重点)

本文详细解析了电商项目中SSM(Spring、SpringMVC、MyBatis)架构的配置文件,包括web.xml的启动配置、spring.xml的数据源、事务管理及组件扫描,以及springmvc.xml的包扫描、编码和文件上传设置。这些配置对于理解和搭建SSM项目至关重要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

把web.xml和springmvc放在同一目录下,把spring.xml放在resource目录下

 

1、web.xml

主要是配置web项目启动时加载的信息,

比如<context-param/>配置参数,

<listener/>配置你的监听器,

<filter/>配置过滤器,

<servlet/>配置你的servlet实现。

web.xml里面有spring.xml、springmvc.xml的引用。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         id="WebApp_ID" version="2.5">

    <display-name>Archetype Created Web Application</display-name>

    //这里配置的编码过滤器
    <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>


    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>



    //将spring.xml引入进行,取得名字叫applicationContext.xml
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:applicationContext.xml
        </param-value>
    </context-param>


    //将springmvc引入进来,取的是默认的名字dispatcher-servlet.xml
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>or
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值