springmvc 配置静态资源 无效

发布于 2022-09-04 07:01:11 字数 5355 浏览 11 评论 0

web.xml

<!-- log4j日志打印配置文件 -->
    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>classpath:log4j.properties</param-value>
    </context-param>
    <!-- 不知道是什么鬼,解决项目启动时报错 -->
    <context-param>
        <param-name>spring.liveBeansView.mbeanDomain</param-name>
        <param-value>default</param-value>
    </context-param>
    <!-- 防止内存泄漏的监听器 -->
    <listener>
        <listener-class>
            org.springframework.web.util.IntrospectorCleanupListener
        </listener-class>
    </listener>
    <!-- 然后是filter -->
    <!-- 编码过滤器 -->
    <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>
    <!-- 用户登录session过滤器 -->
    <filter>
        <filter-name>sessionFilter</filter-name>
        <filter-class>com.gonethen.utils.SessionFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>sessionFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- springmvc主配置 -->
    <!-- 最后为controller加载成bean提供依赖注入 -->
    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:springmvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

springmvc.xml

<mvc:default-servlet-handler />
<mvc:resources location="/" mapping="/**/*.js"/>  
<mvc:resources location="/" mapping="/**/*.css"/>  
<mvc:resources location="/im/" mapping="/im/**"/>
<mvc:resources location="/common/" mapping="/common/**"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <!-- 使用前缀和后缀 -->
    <property name="prefix" value="/WEB-INF"></property>
    <property name="suffix" value=".jsp"></property>
</bean>
<mvc:interceptors>
    <mvc:interceptor>
        <mvc:mapping path="/**"/>
        <bean class="com.gonethen.utils.PermissionInterceptor"></bean>
    </mvc:interceptor>
</mvc:interceptors></pre>

项目结构
图片描述

启动日志
图片描述
login.jsp页面


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>LOGIN</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="format-detection" content="telephone=no">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="alternate icon" type="image/png" href="<c:url value="/im/favicon.ico"/>">
</head>
<body>
    <header>
    </header>
    <main>
</main>
    <jsp:include page="/common/footer.jsp" flush="true" />
    <script type="text/javascript" src="<c:url value="/js/login.js"/>"></script>
</body>
</html>

footer.jsp页面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<body>
    <footer class="am-footer am-footer-default">
    </footer>
    <script type="text/javascript" src="<c:url value="/js/amazeui.dialog.min.js"/>"></script>
    <script type="text/javascript" src="<c:url value="/js/common.js"/>"></script>
</body>
</html>

按说配置mvc:resources 就可以不被拦截和过滤了吧?结果拦截器过滤器都没通过。
求问大神们,看看问题出在哪里了,这问题憋得我两个月没有啪啪啪了。。。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼趣 2022-09-11 07:01:11
 <mvc:resources location="/css/" mapping="/css/**"/> 
 <mvc:resources location="/images/" mapping="/images/**"/> 
 <mvc:resources location="/js/" mapping="/js/**"/> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文