P
P
parkito2016-08-29 13:45:06
Java
parkito, 2016-08-29 13:45:06

What is the difference between redirect and requestDispatcher?

Hello. Help, please, to solve a problem. I need the servlet to redirect the user to the specified page. There are two ways to do this.

req.getRequestDispatcher("/demo/new.jsp").forward(req, resp);
//или
       resp.sendRedirect("/demo/new.jsp");


In the case of a redirect, everything works as intended, but there is no transition with getRequestDispatcher . The user stays on the servlet page. Tell me what am I missing?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2016-08-29
@zolt85

And so, the differences.
forward:
redirect:
Simply put, through forward you can return content from another resource, another jsp. This does not change the original URL.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question