if ((a.indexOf(path_1) != -1)==true) {
System.out.println("trtruetruetruetruetruetruetruetruetruetrueue");
chain.doFilter(request, response);
}else{
System.out.println("falsefalsefalsefalsefalsefalsefalsefalse");
httpResponse.sendRedirect(location);
}为什么我的重定向不跳转,如果我放到true就可以跳,怎么办啊?解决全给分吧

解决方案 »

  1.   

    恩。。好的
    public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chain) throws IOException, ServletException {
    // TODO Auto-generated method stub
    response.setContentType("text/html;charset=utf-8");
    System.out.println("userService=" + userService);
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse =(HttpServletResponse) response;
    HttpSession session = httpRequest.getSession();
    String name = session.getAttribute("auser").toString();
    List list = userService.QueryRole(name);
    path=ServletActionContext.getRequest().getHeader("referer"); 
    path_1 =path.substring(path.lastIndexOf("ttms/"),path.lastIndexOf(""));
    System.out.println("path==="+path_1);
    String NoFilter="";
    String a = null;
    for (int i = 0; i < list.size(); i++) {
    a = list.get(0).toString();
    System.out.println("aaaa==="+a);
    }
    boolean c=(a.indexOf(path_1) != -1);
    System.out.println("cccccc====" + c);
    if ((a.indexOf(path_1) != -1)==true) {
    System.out.println("trtruetruetruetruetruetruetruetruetruetrueue");
    chain.doFilter(request, response);
    }else{
    System.out.println("falsefalsefalsefalsefalsefalsefalsefalse");
    httpResponse.sendRedirect(location);
    }
    }
      

  2.   

    所有的值都得到了,而且控制台可以打印false
      

  3.   

    不跳转是什么情景?没报错?没提升机? 没任何反应? location是神马东西
      

  4.   

    你是下跳到 http://www.baidu.com 看有效果吗
      

  5.   


    localhost里面写了我的路径,没报错,也没提示哦。、在true里面就可以。。
      

  6.   


    百度也不可以跳转,他根本就没运行到那个重定义httpResponse.sendRedirect,,为什么,为什么。
    但是我跳转路径是Struts2的.action路径<result></result>
      

  7.   

    if ((a.indexOf(path_1) != -1)==true) {
    System.out.println("trtruetruetruetruetruetruetruetruetruetrueue");
    chain.doFilter(request, response);
    }else{
    System.out.println("falsefalsefalsefalsefalsefalsefalsefalse");
    httpResponse.sendRedirect(location);
    }
    你的意思是页面上打印出来的是trtruetruetruetruetruetruetruetruetruetrueue么?
    那就是执行了第一个方法呗。
    如果打印falsefalsefalsefalsefalsefalsefalsefalse还没有跳转,那就是你的xml没有配置上相应的路径。
      

  8.   

    你好!!重定义在Xml中也要配置相应的路径么?
      

  9.   

    你XML里  配置 <result name="input"> 了么
      

  10.   

    JSP页面可以,但是action的就不行、
    java.lang.IllegalStateException
    at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407)
      

  11.   

    重定向如果是html什么的不用设,但是你重定向的如果是一个action就必须要设定了。
    另外告诉我,你页面上显示的是falsefalsefalse还是truetruetruetruetrue
      

  12.   


    不是的,我重定义的是jsp的页面,因为我要做页面权限   ,在我点击<a herf=".action">点击</a>的时候,过滤器过滤一遍。另外我页面打印的是falsefalsefalse
      

  13.   

    那就是其实重定向这个方法被执行,只是跳转不成功是吧?
    jsp和html一样,不用xml设定。
    我想你的思路是跳转某个页面的之前,先确定下session中是否存在用户,如果不存在就重定向到登陆页面是么?
      

  14.   


    不是哦,,页面与我数据库存的权限对应,如果不存在,则重定义到我的localhost(权限不足)提示页面。
    但是我这个为什么不会跳转,是不是Struts的原因了?
      

  15.   

    httpResponse.sendRedirect(location);httpResponse.sendRedirect("");这里面你填的是localhost?
    你改成index.html
    看跳不跳转,
    即使不跳转,把浏览器上的地址发给我
      

  16.   

    http://localhost:8080/ttms/admin/user!LimitsLogin.action?newstype=1
    是的,还是不跳转。
      

  17.   


    localhost里面我是String localhost="index.jsp",其实是一样的。 但是那个为什么不跳转。是不是和我Struts配置起冲突了。
    <!--Struts配置-->
    <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping> <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <!--Filter配置-->
    <filter> 
        <filter-name>testFilter</filter-name>
        <filter-class>com.ttms.dao.testFilter</filter-class>  
     </filter>
       <filter-mapping>
       <filter-name>testFilter</filter-name>
       <url-pattern>/admin/*</url-pattern>    
       </filter-mapping> 
      

  18.   

    system.out.println("1");
    response.sendRedirect("");这里面你填的是localhost?
    system.out.println("2");
    判断这句话执行了没有.
    另外看你的地址,/ttms/admin/user!LimitsLogin.action?newstype=1还停留在action中未动
      

  19.   

    框架,2执行到了。可能是页面没动,获取到的还是true吧。