|
1. What is the difference between HttpServlet and GenericServlet? A GenericServlet has a service() method to handle requests. HttpServlet extends GenericServlet added new methods doGet() doPost() doHead() doPut() doOptions() doDelete() doTrace() methods Both these classes are abstract. 2. What's the difference between servlets and applets? Servlets executes on Servers. Applets executes on browser. Unlike applets, however, servlets have no graphical user interface. 3. What are the uses of Servlets? A servlet can handle multiple requests concurrently, and can synchronize requests. Servlets can forward requests to other servers and servlets. Thus servlets can be used to balance load among several servers. 4. When doGET() method will going to execute? When we specified method='GET' in HTML Example : < form name='SSS' method='GET'> 5. When doPOST() method will going to execute? When we specified method='POST' in HTML < form name='SSS' method='POST' > 6. What is the difference between Difference between doGet() and doPost()? GET Method : Using get method we can able to pass 2K data from HTML All data we are passing to Server will be displayed in URL (request string).
POST Method : In this method we does not have any size limitation. All data passed to server will be hidden, User cannot able to see this info on the browser. 7. What is the servlet life cycle? When first request came in for the servlet , Server will invoke init() method of the servlet. There after if any user request the servlet program, Server will directly executes the service() method. When Server want to remove the servlet from pool, then it will execute the destroy() method 8. Which code line must be set before any of the lines that use the PrintWriter? setContentType() method must be set. 9. Which protocol will be used by browser and servlet to communicate ? HTTP 10. In how many ways we can track the sessions? Method 1) By URL rewriting
Method 2) Using Session object Getting Session form HttpServletRequest object HttpSession session = request.getSession(true); Get a Value from the session session.getValue(session.getId()); Adding values to session cart = new Cart(); session.putValue(session.getId(), cart); At the end of the session, we can inactivate the session by using the following command session.invalidate(); Method 3) Using cookies Method 4) Using hidden fields
|