2012-01-25 45 views
0

我有一個過濾器,以記錄他們處理請求,這樣我就可以跟蹤哪些會話在什麼時候什麼請求參數打的頁面。非常棒......從jsp發佈到jsp,或直接調用jsp。當窗體發佈到轉發該請求到一個新的JSP一個servlet,但是,我無法看到哪個JSP請求被轉發到。如何從過濾器確定從RequestDispatcher轉發哪個頁面?

例如,假設我有一個登錄頁面,其職位,以一個LoginServlet,然後將請求轉發給任一的index.jsp或index1.jsp。我如何從請求中確定LoginServlet是否返回i​​ndex.jsp或index1.jsp?

這是使用2.3 servlet規範一個Java 1.5環境。

public class PageLogFilter implements Filter { 

FilterConfig filterConfig = null; 
public void init(FilterConfig filterConfig) throws ServletException { 
    this.filterConfig = filterConfig; 
} 
public void destroy() { 
    this.filterConfig = null; 
} 

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 
    throws IOException, ServletException { 
    try { 
     if (request instanceof HttpServletRequest) { 
      HttpServletRequest req = (HttpServletRequest) request; 
      HttpSession session = req.getSession(false); 

       //For non-forwards, I can call req.getRequestURI() to determine which 
       //page was returned. For forwards, it returns me the URI of the 
       //servlet which processed the post. I'd like to also get the URI 
       //of the jsp to which the request was forwarded by the servlet 
      } 
     } 
    } catch (Exception e) { 
     System.out.println("-- ERROR IN PageLogFilter: " + e.getLocalizedMessage()); 
    } 
    chain.doFilter(request, response); 
} 
} 

回答

0

+0

嗨Bozho呼叫request.getRequestURI()。不幸的是,這是行不通的。 – rpierce

+0

它返回什麼? – Bozho

+0

它返回服務servlet的URI,例如「/ LoginServlet」 – rpierce

相關問題