在过滤器中
   public void doFilter(ServletRequest req, ServletResponse res,
            FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        request.getRequestURI();//此句取的是页面的元素JS路径、图片等,而不是我访问的地址。而且要执行过滤器好多次。
    }
想请教高手 request.getRequestURI()怎么取实际地址?

解决方案 »

  1.   

    文件系统中的路径?要用 HttpServletRequest  的 getPathInfo
      

  2.   

    你的方法取的值是NULL
      

  3.   

    楼主debug模式,查看request的全部参数,不就可以看到全部信息了么, request.getRequestURI()得到的是拼接地址,很可能包名和图片/js
    名称用的是一样的名字
      

  4.   

    // 获得请求方式
    String method = request.getMethod();
    System.out.println("method:" + method);
    // 获得请求的资源
    String uri = request.getRequestURI();
    String url = request.getRequestURL().toString();
    System.out.println("uri:" + uri);
    System.out.println("url:" + url);

    // 获得web应用名称
    String contextPath = request.getContextPath();
    System.out.println("contextPath:" + contextPath);

    // 获得地址后的字符串参数
    String queryString = request.getQueryString();
    System.out.println("queryString:" + queryString);

    // 获取客户机的信息(IP地址)
    String remoteAddr = request.getRemoteAddr();
    System.out.println("remoteAddr:" + remoteAddr);
      

  5.   

    奇了怪了,我反复试验后,发现用request.getRequestURI()取地址。以.jsp结尾和.do结尾的都可以取到,就是以.action结尾的取不到。
      

  6.   

    那是在web.xml里配置的拦截器,以.do和.jsp会做拦截,想拦截.action的请求的话,配置上添加.action就可以了
      

  7.   

    根本就取不到.action的地址,无法拦。
      

  8.   

    web.xml里肯定有这样的配置
    <servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    你加一个
    <servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>*.action</url-pattern>
    </servlet-mapping>
      

  9.   

    MVC 微框架 http://www.verejava.com/?section_id=1697715673191
      

  10.   

    过滤器拦截了所有请求,配置一下只拦截 .do .action
      

  11.   

    请问一下如何配置拦截 .do .action?
      

  12.   

    Spring MVC
      

  13.   

    ServletActionContext.getRequest.getRequestUrl
      

  14.   

    类型转换成其他的Request再试