Doubt with Servlet

Asked

Viewed 120 times

7

Hello, I have a question with Servlet’s.

Picture the picture:

raiz /
     / formulario.jsp
     / Servlet
     / retornos / retorno.jsp

The form sends to Servlet the data by post or get!

After this submission, using Requestdispatcher what actually occurs?

A) return.jsp is included in.jsp form

B) Servlet redirects data from it to return.jsp

C) Servlet includes return.jsp in its body as if printing a text?

What happens in reality?

  • 1

    Using Requestdispatcher#include, or Requestdispatcher#forward?

  • Requestdispatcher#forward

  • the name itself already says... #forward will be redirected.. #include will be included

  • @Pedrolaini. A), B) or C) is the correct alteration?

  • see the answer

1 answer

5

Behold that link that shows example of 2 implementations.

To correct alternative to your question will depend on which Requestdispatcher method you will use.

It has two methods: forward(Servletrequest request, Servletresponse) and include(Servletrequest request, Servletresponse)

In the cited link, it is implementing a login page as follows:

  • Displays a form with login/password.
  • User enters user and password and gives Submit.
  • If login/password is incorrect: it gives a include showing the message that login/password is incorrect . include = on the same screen
  • If login/password is correct: it gives a forward to another screen saying "Welcome, so-and-so!" forward = other screen

See also the documentation of RequestDispatcher

Browser other questions tagged

You are not signed in. Login or sign up in order to post.