Thursday 19 January 2017

What is URL rewriting? What is servlet chaining? Are Servlets thread safe? What is the purpose of RequestDispatcher Interface?

What is URL rewriting?
URL rewriting is a method of session tracking in which some extra data is appended at the end of each URL. This extra data identifies the session. The server can associate this session identifier with the data it has stored about that session.

What is servlet chaining?
Servlet Chaining is a method where the output of one servlet is piped into a second servlet. The output of the second servlet could be piped into a third servlet, and so on. The last servlet in the chain returns the output to the Web browser.

Are Servlets thread safe?
Servlet is not thread safe but we can make it as a thread safe by implementing that servlet class to SingleThreadModel

public class SurveyServlet extends HttpServlet                            implements SingleThreadModel
{
servlet code here..
...
}

Servlet containers usually manage concurrent requests by creating a new Java thread for each request. The new thread is given an object reference to the requested servlet, which issues the response through the same thread. This is why it is important to design for concurrency when you write a servlet, because multiple requests may be handled by the same servlet instance

What is the purpose of RequestDispatcher Interface?
The RequestDispacher interface provides the facility of dispatching the request to another resource it may be html, servlet or jsp

No comments:

Post a Comment