Question

I know that a forward preserves everything, including the method. But is there a way around forwarding a POST as a GET?

I.e. is there a way to make the forward below become a GET so that the page to which we forward can access my session attribute?

 @Override
  protected void doPost(final HttpServletRequest req,
          final HttpServletResponse resp) throws ServletException, IOException {
      ...
      req.setAttribute("session", session);
      req.getRequestDispatcher("/myPage.jsp").forward(req, resp);
  }
Was it helpful?

Solution

See HttpServletRequestWrapper.

You wrap the request so that getMethod() returns GET then pass the wrapped request to your request dispatcher.

OTHER TIPS

The page can access the session and request attributes without any problem, because it is a single request when you forward.

I can't see your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top