0

1st question: Which scope object to be used if:

  1. You wish to maintain the user profile that the customer needs to enter in multiple pages.
  2. You wish to validate the user id and password entered by user suing another servlet but in the same web application.

2nd question: The RequestDispatcher object has two methods, include() and forward(). What is the difference?

3rd question: Servlet uses a javax.servlet.http.HttpServletResponse object. How do you use it to return Text data and Binary data?

2

2 Answers 2

2

(a) Session Scoped

RequestDispather.forward() Once you forward the request from say Servlet A to any other Servlet/JSP control gets transferred from Servlet A to forwarded patrty & it never returns back to A for that request.

RequestDispather.Include() In include what you are doing is if Servlet A(Above example) is including the response of other Servlet/JSP(say B or B.jsp) so momentarily Control goes to B or B.jsp (they will genrate the response) control comes back to A & generated response is added in A's Response.

check HttpServletResponse API for response writing

Sign up to request clarification or add additional context in comments.

Comments

0
  1. Answer:

    Forward() method is used to forward the request from Servlet to Servlet/JSP/HTML or JSP to Servlet/JSP/HTML

    include() method is used to include the response of Servlet or JSP in another Servlet or JSP

    1. Answer:

    You can create a separate Servlet class to validate User ID and Password for another Servlet class,it can be done by Servlet Chaining concept. In the validation Server class,call request dispatcher to forward the response to Main Servlet class.

eg.

RequestDispatcher rd=req.getRequestDispatcher("url/servlet name"); rd.forward(req,res)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.