qq_36930706
林谿
采纳率60%
2017-10-09 07:01

配置拦截器后JSP页面找不到引用的javascript

已采纳

拦截器配置成功后原jsp页面引用的js404了
js引用如下

 <script type='text/javascript' src='<%=basePath%>admin/js/aclock.js'></script>
    <script type="text/javascript" src="<%=basePath%>admin/eventJS/sharingJS.js"></script>

web.xml如下:

 <filter>
        <filter-name>Login</filter-name>
        <filter-class>com.xxxx.Util.LoginFilter</filter-class>
        </filter>
    <filter-mapping>
        <filter-name>Login</filter-name>
        <url-pattern>/admin/*</url-pattern>
        <url-pattern>/views/*</url-pattern>
    </filter-mapping>
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/js/*</url-pattern>
        <url-pattern>/css/*</url-pattern>
        <url-pattern>/images/*</url-pattern>
    </servlet-mapping>

拦截器如下:

 public void doFilter(ServletRequest arg0, ServletResponse arg1,
            FilterChain arg2) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) arg0;
        HttpServletResponse resp = (HttpServletResponse) arg1;
        HttpSession session = req.getSession();
        String path = req.getRequestURI();
        System.out.println(path);
        String admin_account = (String) session.getAttribute("admin_account");
     if(path.indexOf("image.jsp") > -1){
             arg2.doFilter(req, resp);
             return;
         }else {// 如果不是login.jsp进行过滤
             if (admin_account == null || "".equals(admin_account)) {
                    resp.sendRedirect("/stone-bi/index.jsp");
                } else {
                    // 已经登陆,继续此次请求
                    arg2.doFilter(req, resp);
                }
         }
    }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • longlong3207 longlong3207 4年前

    你的这个项目是ssm项目吗》?
    如果是ssm项目的话你要在spring的配置文件中配置静态资源

    <mvc:resources location="/resources/" mapping="/resources/**"/>
    
    
    点赞 1 评论 复制链接分享
  • qq_36930706 林谿 4年前

    不是spring项目才头疼,谢谢啦,我把所有静态资源挪外面就正常了

    点赞 评论 复制链接分享