Java Servlets Question and Answers

21. What are the objects that are received when a Servlet accepts a call from Client?
 
  • The objects are ServletRequest and ServletResponse. The ServletRequest encapsulates the communication from the client to the server.
  • While ServletResponse encapsulates the communication from the servlet back to the client.
 
Your Name Your Email-ID
Your Answer
22. How to track a user session in Servlets?
  The interface HTTPSession can be used to track the session in the Servlet. Following code can be used to create session object in the Servlet: HTTPSession session = req.getSession(true).
 
Your Name Your Email-ID
Your Answer
23. Which are the different ways you can communicate between servlets?
 
    Below are the different ways of communicating between servlets:-
  • Using RequestDispatcher object.
  • Sharing resource using "ServletContext()" object.
  • Including response of the resource in the response of the servlet.
  • Servlet chaining.
 
Your Name Your Email-ID
Your Answer
24. Why HTTP protocol called as a stateless protocol?
  A protocol is stateless if it cannot remember difference between one client request and the other. HTTP is a stateless protocol because each request is executed independently without any knowledge of the requests that came before it.
 
Your Name Your Email-ID
Your Answer
1234567891011 Page 6 of 11