Soul柒月 2016-03-13 06:42 采纳率: 20%
浏览 1626
已采纳

新手求助:filter过滤器的问题

web.xml配置

<filter>
        <filter-name>loginInterceptor</filter-name>
        <filter-class>com.cbt.Interceptor.LoginInterceptor</filter-class>
        <init-param>
            <param-name>loginPage</param-name>
            <param-value>main_login</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>loginInterceptor</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>loginInterceptor</filter-name>
        <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>loginInterceptor</filter-name>
        <url-pattern>*.html</url-pattern>
    </filter-mapping>
    <servlet>
        <servlet-name>cbtconsole</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring/springmvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>cbtconsole</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

springmvc配置

<bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <!-- 资源映射:因为servlet-mapping会拦截所有请求.需要过滤掉静态资源请求 -->
    <mvc:resources location="/WEB-INF/css/" mapping="/css/**" />
    <mvc:resources location="/WEB-INF/js/" mapping="/js/**" />

过滤器代码

@Override
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        HttpServletResponse httpServletResponse = (HttpServletResponse) response;
        String urlPath = httpServletRequest.getRequestURL().toString();
        String value = jedisClient.get("key1");
        System.out.println(urlPath+"---"+value);
        if (value !=null) {
            chain.doFilter(request, response);
        }else{
            httpServletResponse.sendRedirect(urlPath + loginPage);
        }
    }

    @Override
    public void init(FilterConfig config) throws ServletException {
        //context-param –> listener –> filter –> servlet
        loginPage = config.getInitParameter("loginPage");
        ServletContext context = config.getServletContext();
        ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(context);
        jedisClient = (JedisClient) ctx.getBean("jedisClient");  
    }

输入localhost:8080进入过滤器后直接死循环了.
求大神指点

  • 写回答

2条回答 默认 最新

  • Soul柒月 2016-03-13 07:03
    关注

    是不是大神都不屑回答这种问题.小白真心求解答

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 MATLAB动图问题
  • ¥15 有段代码不知道怎么理解,const isToken = (config.headers || {}).isToken === false
  • ¥100 采用栈和深度优先算法对我的代码进行修改显示路径
  • ¥15 pointnet2包安装
  • ¥20 射频功率问题,解答者有酬谢!
  • ¥80 构建降雨和积水的预测模型
  • ¥15 #Qt Transform setTransform()在鼠标拖动移动视角是一致在原地不动,无法变换视角(细微观察似乎视图有在原地抖动),无法变换视角(细微观察似乎视图有在原地抖动)
  • ¥50 如何利用无人机拍摄的数码照片测量鸟卵的长短径
  • ¥100 github贡献者给与奖励
  • ¥15 使用DS18B20+ESP8266获取温度数据返回-127.00