Java JSB Servlets Question and Answers

37. How you can destroy the Session in Servlet?
  • You can call invalidate() method on the session object to destroy the session.
  • E.g. session.invalidate().
Your Name Your Email-ID
Your Answer
38. 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
39. Can you explain taglib directives?
  Taglib are also termed as JSP tag extensions. They provide a way of encapsulating reusable functionality on JSP pages. One of the biggest drawbacks of scripting environments such as JSP is that it's easy to get carried away without thinking about how it will be maintained and grown in the future.
There are four files which play an important role:
  • Main class file which encapsulates the logic
  • Tag library descriptor file
  • Web.xml file which has the tag library descriptor file location
  • Finally the JSP file which calls it.
Your Name Your Email-ID
Your Answer
40. Why do you use Session Tracking in HTTPServlet?
  • In HTTPServlet you can use Session Tracking to track the user state.
  • Session is required if you are developing shopping cart application or in any e–commerce application.
Your Name Your Email-ID
Your Answer

Page 10 of 15