Posted by
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!
- 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?
- What is the difference between http GET and POST methods ?
- There are 10 servlets in your web application, and they are frequently used (sticky Servlet). How will you optimize their loading?
- How will you communicate across Servlets? (or, how will you achieve Inter Servlet communication?)
- Hope, you know the difference between RequestDispatcher.forward() and RequestDispatcher.sendRedirect(). So, which one is desirable to use?
- What is the class path hierarchy for a Servlet?
- 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:
- 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.
- 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.
- 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.
- Use RequestDispatcher.forward() and RequestDispatcher.include();
- RequestDispatcher.sendRedirect() is desirable. Because, forward() can’t work across different JVM.
- First, lookup in WEB-INF/classes, then WEB-INF/lib then from tomcat’s central library folder (<tomcat-home>/lib)
- 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:
Related posts brought to you by Yet Another Related Posts Plugin.
Hi Na,
I would like more questions of these kinds.
plz send me such interesting questions..
thanks
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.
Hi , This site has very useful techie questions.Good job, Please have more questions of this kind
hai revathy
hru?where is ur palce?
please contacts 2 me.
i will chat with u.
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
For more interview questions, please refer http://pragyarawal.blogspot.com