springmvc 配置静态资源 无效
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)