Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I redirect to the current page in Servlet Filter?

I have a page say: /myapp/test.jsp?queryString=Y. The filter needs to redirect to current page. It should go to /myapp/test.jsp (without the query string). The below seems to bring it to to the context root: /myapp. I am running in WAS6.1.

public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest httpReq = (HttpServletRequest) req;
        HttpServletResponse httpResp = (HttpServletResponse) resp;
{
   boolean blnNeedToRedirect = true;
   if (blnNeedToRedirect) {
      httpResp.sendRedirect(".");
      return;
   }

   chain.doFilter(req, resp);
}
like image 327
JeffJak Avatar asked Jan 24 '23 03:01

JeffJak


1 Answers

Use HttpServletrequest.getRequestURI. This should work for you:

httpResp.sendRedirect(httpReq.getRequestURI());
like image 179
skaffman Avatar answered Jan 29 '23 20:01

skaffman