У меня есть фильтр, который обрабатывает запросы для их регистрации, поэтому я могу отслеживать, какой сеанс попал на страницу в какое время с помощью каких параметров запроса. отлично работает ... отправляет из jsp в jsp или делает прямой вызов jsp. Однако, когда форма отправляется в сервлет, который перенаправляет этот запрос на новый jsp, я не могу видеть, к какому jsp был отправлен запрос.Как определить фильтр, который был отправлен jsp из запроса RequestDispatcher.forward?
Например, предположим, что у меня есть страница входа в систему, которая отправляется в LoginServlet, которая затем перенаправляет запрос на index.jsp или index1.jsp. Как я могу определить из запроса, будет ли LoginServlet возвращать index.jsp или index1.jsp?
Это в среде java 1.5 с использованием спецификации сервлета 2.3.
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);
}
}
возможно дубликат [Как определить из фильтра, стр обслуживала вперед от RequestDispatcher?] (Http://stackoverflow.com/questions/9011106/how-to-define-from-a-filter-which-page-serviced-a-forward-from-requestdispatc) – Bozho