springMVC依赖及配置

1.依赖

	<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.3.9</version>
        </dependency>
        <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
<!--            使用注解配置mvc依赖-->
    </dependency>
        <dependency>
        <groupId>javax.annotation</groupId>
        <artifactId>javax.annotation-api</artifactId>
        <version>1.3.2</version>
    </dependency>
        <!-- https://mvnrepository.com/artifact/javax.servlet/jsp-api -->
        <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.0</version>
        <scope>provided</scope>
    </dependency>
<build>
<resources>
    <resource>
    <directory>src/main/java</directory>
    <includes>
    <include>**/*.properties</include>
    <include>**/*.xml</include>
</includes>
    <filtering>false</filtering>
</resource>
    <resource>
    <directory>src/main/resources</directory>
    <includes>
    <include>**/*.properties</include>
    <include>**/*.xml</include>
</includes>
    <filtering>false</filtering>
</resource>
</resources>
</build>

2.web.xml 配置

	<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <!-- 配置DispatcherServlet -->



    <servlet>

    <servlet-name>SpringMVC</servlet-name>

    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

    <!-- 配置spring的配置文件 -->



    <init-param>

    <param-name>contextConfigLocation</param-name>

    <param-value>classpath:springmvc-servlet.xml</param-value>

</init-param>

    <!-- 启动Tomcat时即初始化该Servlet -->


    <load-on-startup>1</load-on-startup>

</servlet>


    <servlet-mapping>

    <servlet-name>SpringMVC</servlet-name>

    <!-- 拦截所有请求-->


    <url-pattern>/</url-pattern>

</servlet-mapping>
</web-app>

3.springmvc-servlet.xml 配置

	<?xml version="1.0" encoding="UTF-8"?>
<beans xsi:schemaLocation="http://www.springframework.org/schema/beans
       https://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       https://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/mvc
       https://www.springframework.org/schema/mvc/spring-mvc.xsd"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans">
    <!--启用注解-->
    <!-- <context:annotation-config/>-->
    <!-- 启用aop注解-->
    <!-- <aop:aspectj-autoproxy/>-->
    <!--扫描注解-->
    <context:component-scan base-package="com.qiku.studentsys"/>
    <mvc:annotation-driven/>
<!--     <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>-->
<!--     <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!-- /WEB-INF/index.jsp-->
        <!-- 配置前缀 -->
        <property value="/WEB-INF/" name="prefix"/>
        <!-- 配置后缀 -->
        <property value=".jsp" name="suffix"/>
        <!-- 经过以上配置后, -->
        <!-- 当前项目中的jsp文件都应该放在/WEB-INF/下 -->
    </bean>
<!--     <bean name="/index" class="com.qiku.studentsys.controller.StudentController"/>-->
<!--     <bean name="/index" class="com.qiku.studentsys.controller.StudentController1"/>-->
</beans>

4.跳转乱码处理

	<!-- 处理乱码-->
    <filter>
        <filter-name>encoding</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>encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值