Sunday, January 31, 2010

JSP Servlet Interview questions

Question1:After hitting submit button, a JSP page processes a database transaction. You have accidentally closed the browser window. Will the database transaction continue or will get over?


Answer:
The database transaction will still continue; Because a Servlet thread was created when you hit the JSP page and that runs the database transaction. Closing the browser window will not kill the Servlet thread.

Question2:What is the difference between http GET and POST methods ?


Answer:
GET method passes the form fields as part of URL, but POST method wraps or encrypts the form fields in request data; b) Also, you can pass only 255 characters to the action page with GET method.

Question:3 There are 10 servlets in your web application, and they are frequently used (sticky Servlet). How will you optimize their loading?


Answer:
Add tag to the Servlet in web.xml. This will load your Servlet on startup, and doXXX() method will be ready for any further requests.

Question:4. How will you communicate across Servlets? (or, how will you achieve Inter Servlet communication?)


Answer:
Use RequestDispatcher.forward() and RequestDispatcher.include();

Question:5. You know the difference between RequestDispatcher.forward() and RequestDispatcher.sendRedirect(). So, which one is desirable to use?


Answer:
RequestDispatcher.sendRedirect() is desirable. Because, forward() can’t work across different JVM.

Question:6. What is the class path hierarchy for a Servlet?


Answer:
First, lookup in WEB-INF/classes, then WEB-INF/lib then from tomcat’s central library folder (/lib)

Question:7. You can’t read files (located out of tomcat directory) from JSP and Servlets for security purpose. But, how will you access those files from JSP or Servlets, in case if you need them?


Answer:
Any class from WEB-INF/classes or WEB-INF/lib can access files. So, use those classes to do the job for your JSP and Servlets.

Courtesy:http://excusemeworld.com

No comments:

Post a Comment