リクエストをログに記録するためにリクエストを処理するフィルターがあるので、どのセッションがどのリクエスト パラメータでいつページにヒットしたかを追跡できます。うまく機能します... jspからjspへの投稿、またはjspへの直接呼び出しを行います。ただし、そのリクエストを新しい JSP に転送するサーブレットにフォームがポストされると、リクエストがどの JSP に転送されたかを確認できません。
たとえば、LoginServlet に投稿するログイン ページがあり、その後、リクエストを index.jsp または index1.jsp に転送するとします。LoginServlet が index.jsp または index1.jsp を返すかどうかをリクエストから判断するにはどうすればよいですか?
これは、2.3 サーブレット仕様を使用する 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, for
//example "index.jsp" or "index1.jsp"
}
} catch (Exception e {
System.out.println("-- ERROR IN PageLogFilter: " + e.getLocalizedMessage());
}
chain.doFilter(request, response);
}
}