The HttpSession interface can be used to view and manipulate information about a session such as the session identifier and creation time, and to bind objects to the session. A new session object may be created
protected void doGet(HttpServletRequest request,HttpServletResponse response) {
HttpSession session = request.getSession(true);
//. . .
}
The session.setAttribute and session.getAttribute methods are used to bind objects to the session.
A servlet may forward a request to another servlet if further processing is required. You can achieve this by dispatching the request to a different resource using RequestDispatcher, which can be obtained from HttpServletRequest.getRequestDispatcher or ServletContext.getRequestDispatcher. The former can accept a relative path, whereas the latter can accept a path relative to the current context only
prprotected void doGet(HttpServletRequest request,HttpServletResponse response) {
request.getRequestDispatcher("bank").forward(request, response);
//. . .
}
In this code, bank is another servlet deployed in the same context.
The ServletContext.getContext method can be used to obtain ServletContext for foreign contexts. It can then be used to obtain a RequestDispatcher, which can dispatch requests in that context.








