M
M
Miron2020-03-29 09:14:14
Java
Miron, 2020-03-29 09:14:14

What is the best way to go from servlet to servlet - via forward(...) or via sendRedirect(...)?

forward gives us the ability to save request and response data for later use. The same can be done by using the Session container ( HTTPSession ) in the case of sendRedirect , although this will impose on us the obligation to pass all the necessary attributes and parameters, which makes the program more rigid. But the thing is, if request is passed via Post , then when we forward the user to another servlet, that servlet will think that it has received a Post method request . This is a problem, but it is solved by introducing the isGet attribute(if you know a way to change the request method field - tell me, I don’t have such information), which will be checked in service (which, unfortunately, will have to be rewritten) or at the beginning of the doPost method (which, in turn, looks like a crutch, better, after all, via service ).
Am I right, maybe there are other ways? Is it really possible to completely replace forward with sendRedirect ? What is the way to use when you need to send information from Post of one servlet to Get of another?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question