Lolo
Lolo

Reputation: 4169

Is there a way to forward a POST as a GET?

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);
  }

Upvotes: 1

Views: 626

Answers (2)

Amir Pashazadeh
Amir Pashazadeh

Reputation: 7322

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.

Upvotes: 0

Adam Gent
Adam Gent

Reputation: 49095

See HttpServletRequestWrapper.

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

Upvotes: 2

Related Questions