• 静态资源过滤


    1、项目目录

    2、index.jsp

    <%--
      Created by IntelliJ IDEA.
      User: Administrator
      Date: 2020/2/27
      Time: 19:26
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>Title</title>
        <script src="js/jquery.min.js" type="text/javascript"></script>
        <script>
            $(function() {
                $("#btn").click(function() {
                    alert(100);
                });
            });
        </script>
    </head>
    <body>
    <button id="btn">按钮</button>
    </body>
    </html>

    3、springmvc.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: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://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc.xsd">
        <!--配置注解扫描包-->
        <context:component-scan base-package="com.ly.mvc"></context:component-scan>
        <!--配置视图解析器-->
        <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/pages/"></property>
            <property name="suffix" value=".jsp"></property>
        </bean>
        <!--过滤静态资源-->
        <mvc:resources location="/js/" mapping="/js/**"/>
        <mvc:resources location="/css/" mapping="/css/**"/>
        <mvc:resources location="/images/" mapping="/images/**"/>
        <mvc:annotation-driven></mvc:annotation-driven>
    </beans>

    4、总结

    在web.xml中配置了springmvc对任何请求都会进行拦截,因此页面中引入jquery.min.js时也会被拦截,解决方法在springmvc.xml中增加过滤静态资源文件的配置

  • 相关阅读:
    小乖乖的Linux历险记
    走近虚拟机与Linux
    Navicat for MySQL数据库管理工具安装和破解
    Spring + Struts + Hibernate 简单封装通用接口
    Java 学习路线图
    Java Mail 发送带有附件的邮件
    Java POI 读取Excel数据转换为XML格式
    Spring + Struts + Hibernate + Bootstrap-table 实现分页和增删改查
    Java 基础知识
    SSH三大框架知识点
  • 原文地址:https://www.cnblogs.com/liuyang-520/p/12376485.html
Copyright © 2020-2023  润新知