GONETHEN 2016-12-09 13:38 采纳率: 0%
浏览 1477
已采纳

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>

项目结构
图片说明

启动日志
图片说明

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 就可以不被拦截和过滤了吧?结果拦截器过滤器都没通过。
求问大神们,看看问题出在哪里了,这问题憋得我两个月没有啪啪啪了。。。

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2016-12-10 15:16
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已采纳回答 11月30日

悬赏问题

  • ¥15 支付宝h5参数如何实现跳转
  • ¥15 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 前后端分离的学习疑问?
  • ¥15 stata实证代码答疑
  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 zigbee终端设备入网失败