Welcome Message

Hi, welcome to my website. This is a place where you can get all the questions, puzzles, algorithms asked in interviews and their solutions. Feel free to contact me if you have any queries / suggestions and please leave your valuable comments.. Thanks for visiting -Pragya.

November 1, 2009

Nice Servlets and Jsp questions

What is session?
A : The session is an object used by a servlet to track a user's interaction with a Web application across multiple HTTP requests. The session is stored on the server.

What is servlet context ?
A: The servlet context is an object that contains a information about the Web application and container. Using the context, a servlet can log events, obtain URL references to resources, and set and store attributes that other servlets in the context can use.

What is a servlet ?
A: servlet is a java program that runs inside a web container.

Can we use the constructor, instead of init(), to initialize servlet?
A: Yes. But you will not get the servlet specific things from constructor. The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructor a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext.

How do I include static files within a JSP page?
A: Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase.

How can I implement a thread-safe JSP page?
A :You can make your JSPs thread-safe adding the directive <%@ page isThreadSafe="false" % > within your JSP page.

What is a Expression?
A: Expressions are act as place holders for language expression, expression is evaluated each time the page is accessed. This will be included in the service method of the generated servlet.

Reference : http://www.javacertificate.net/jsp_iqns.htm

No comments: