21
November

Many people have requested to post JSP Servlets scenario based interview questions. Yet, even I too have been thinking of posting J2EE related interview questions. So, let’s first start with JSP and Servlets (scenario based) interview questions.

This time, I am giving the answers  But, I am pretty lazy to type the entire answer!

  1. 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?
  2. What is the difference between http GET and POST methods ?
  3. There are 10 servlets in your web application, and they are frequently used (sticky Servlet). How will you optimize their loading?
  4. How will you communicate across Servlets? (or, how will you achieve Inter Servlet communication?)
  5. Hope, you know the difference between RequestDispatcher.forward() and RequestDispatcher.sendRedirect(). So, which one is desirable to use?
  6. What is the class path hierarchy for a Servlet?
  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?

Answers:

  1. 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.
  2. a) 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.
  3. Add <load-on-startup> tag to the Servlet in web.xml. This will load your Servlet on startup, and doXXX() method will be ready for any further requests.
  4. Use RequestDispatcher.forward() and RequestDispatcher.include();
  5. RequestDispatcher.sendRedirect() is desirable. Because, forward() can’t work across different JVM.
  6. First, lookup in WEB-INF/classes, then WEB-INF/lib then from tomcat’s central library folder (<tomcat-home>/lib)
  7. 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.

Just let me know, if you want more scenario based questions related to any are under Java/J2EE.

Related posts:

  1. Java Interview Questions, Tricks and Tips. Oh no, this is not an yet another article posting...
  2. Java, J2EE Performance Tuning Interview Questions And, I’m back with some performance related interview questions. The...
  3. Java Threads Interview Questions Many people feel that Threads and Collection APIs are somewhat...
  4. SCWCD 1.4 Vs SCWCD 1.5 (SCWCD 5) Differences In this article, let’s discuss the difference between SCWCD 1.4...
  5. Design Patterns Interview Questions Patterns are so important, if you are giving a software...

Related posts brought to you by Yet Another Related Posts Plugin.

Category : Interview Questions / Java J2EE Interview Questions

Comments

Dinesh July 21, 2009

Hi Na,

I would like more questions of these kinds.

anshul August 12, 2009

plz send me such interesting questions..
thanks

vinay August 17, 2009

hi i liked the questions u have posted on java collections….can u post more scenario based(like which collection to use for different games) questions on java collections.

Thanks in advance.

revathi July 25, 2010

Hi , This site has very useful techie questions.Good job, Please have more questions of this kind

girishkumar August 12, 2010

hai revathy
hru?where is ur palce?
please contacts 2 me.
i will chat with u.

Manishree August 19, 2010

Manivannan,
very good questions are posted on this site.. I need your emailId for further discussion. Is it possible for you to give it.
Thanks,
Manishree

Pragya August 20, 2010

For more interview questions, please refer http://pragyarawal.blogspot.com

Leave a comment

Spam protection by WP Captcha-Free