0

リクエストをログに記録するためにリクエストを処理するフィルターがあるので、どのセッションがどのリクエスト パラメータでいつページにヒットしたかを追跡できます。うまく機能します... 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
            }
        }
    } catch (Exception e) {
        System.out.println("-- ERROR IN PageLogFilter: " + e.getLocalizedMessage());
    }
    chain.doFilter(request, response);
}
}
4

1 に答える 1

0

request.getRequestURI()後に電話するchain.doFilter(..)

于 2012-01-25T22:42:22.647 に答える