JSP

JSP Projects

JSP Project

JSP Interview Questions And Answers
More interview questions and answers

What are cookies?

A Cookie is a small piece of information or messages used to communicate between the web server and the web browser. Your browser stores each message in a small file, called cookie.txt. This information is exchanged between the browser and the server to remember some specific information.


How cookies Work : A command line in the HTML of a document tell the browser to set a cookie of a certain name or value. Here is an example of some script used to set a cookie. Set-Cookie: NAME=VALUE; expir es=DATE; path=PATH; domain=DOMAIN_NAME; secure Cookies are usually run from CGI scripts, but they can also be set or read by Javascript. 


Examples of cookies : 

    * Cookies are used to track web site activity.

    * Cookies are also used for online shopping.

    * Servers also use cookies to provide personalized web pages.


Cookie Security : The easiest way to secure yourself against the supposed dangers of cookies is to get one of the latest browser versions and turn cookies off.

What is JSP?

JSP is a Java technology provides support to generate dynamic page using HTML, XML tag and scriptlets written in the Java programming language. JSP provides us a way to write Java code embedded into the HTML. JSP pages separate the page logic from its design and display.

JSP pages are compiled into servlets and may call JavaBeans components or Enterprise JavaBeans components to perform processing on the server.


JavaServer Pages has two subcategories :

 

  * Tag Libraries

  * JavaServer Pages Standard Tag Library(JSTL).

 

What is lifecycle of JSP?

 Life cycle of JSP :

 

    * JSP page translation,

    * JSP page compilation,

    * load class,

    * create instance,

    * call the jspInit() method,

    * call the _jspService() method, and

    * call the jspDestroy() method. 

What is the difference between JSP and Servlets ?

JSP(Java Server Pages) and Servlets, both are server side executed program and used to generate dynamic web page. Servlets are pure java classes and compiled directly into the .class whereas JSP page is a combination of HTML and java code. First of all JSP is translated into java file and then compiled into servlet. Functionally both are same. Both use the Servlet API to communicate with the web server and the client. Both require a container on the server, such as Tomcat, which provides the environment and VM for the Java program. Servlets are best suited for request processing, handling the business logic while JSP is suitable for content generating (client view). It is easy to include HTML tag in JSP rather than servlet.

What is difference between custom JSP tags and beans?

JSP has its own tag library that you can use in any nuber of pages. You can also create your own tags (Cusustom tags), define attributes and body of the tags and then group your tags into collections called tag library.


To use custom JSP tags, you need to define three separate components:


  * Tag handler class.

  * Tag library descriptor file.

  * JSP file that uses the tag library.

When the first two components are done, you can use the tag by using taglib directive.


JavaBeans are Java utility classes you defined. Beans have a standard format for Java classes. Custom tags and beans accomplish the same goals � encapsulating complex behavior into simple and accessible forms.

Difference between custom JSP tags and beans :


  * Custom tags require more work to set up than do beans.

  * Custom tags can manipulate JSP content, beans cannot.

  * Custom tags usually define relatively self-contained behavior, whereas beans are often defined in one servlet and used in a different servlet or JSP page.

What are the different ways for session tracking?

The concept of session tracking allows you to maintain the relation between the two successive request from the same client (browser). The browser sends the request to the server and server process the browser request generate the response and send back response to the browser. The server is not at all bothered about who is asking for the pages. The server (because of the use of HTTP as the underlying protocol) has no idea that these 2 successive requests have come from the same user. There is no connection between 2 successive requests on the Internet. 


There are three ways of tracking sessions : 

   * Using Cookies.

   * Using URL Rewriting.

   * Using Hidden Form Fields.


 

What mechanisms are used by a Servlet Container to maintain session information?

 The mechanisms used by a Servlet Container to maintain session information : 


a) Cookies


b) URL rewriting


c) Hidden form fields


d) SSL (using HTTPS protocol) Sessions

Difference between GET and POST

Difference between GET and POST : 

  * Client can send information to the server by two methods : GET and POST.

  * The GET method appends parameters (name/value) pairs to the URL. The length of a URL is limited, there is a character restriction of 255 in the URL.  so this method only works if there are only a few parameters.  

  * The main difference between GET and POST is, POST has a body. Unlike GET, parameters are passed in the body of the POST insteat of appending to the URL. We can send large number of data with the POST.  

  * \"GET\" is basically for just getting (retrieving) data whereas \"POST\" may involve anything, like storing or updating data, or ordering a product, or sending E-mail.

  * The data send with the GET method is visible at the browser\'s address bar. Don\'t send important and sensitive data with GET method, use POST.

  * Get is idempotent, means it has no side effects on re-requesting the same thing on the server.

What is servlet mapping?

Servlet mapping controls how you access a servlet. Servlet mapping specifies the web container of which java servlet should be invoked for a url given by client. For this purpose web container uses the Deployment Decriptor (web.xml) file. Servlets are registered and configured as a part of a Web Application. To register a servlet, you add several entries to the Web Application deployment descriptor.


Servlet Mapping : 


<servlet>

  <servlet-name>MyServlet</servlet-name>

  <servlet-class>myservlets.MappingExample</servlet-class>

</servlet>


<servlet-mapping>

  <servlet-name>MyServlet</servlet-name>

  <url-pattern>com/*</url-pattern>

</servlet-mapping>


A developer can map all the servelts inside its web application.

What is servlet context ?

Servlet context defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file. A servlet context object is one per web application per JVM and this object is shared by all the servlet. You can get and set the Servlet context object. You can use servelt context object in your program by calling directly getServletContext() or getServletConfig().getServletContext().

How many JSP scripting elements are there and what are they?

Types of Scripting Elements

  ï¿½ Expressions :

      <%= expression %> :� Evaluated and inserted into the servlet�s output, i.e., results in something like out.print(expression)

  ï¿½ Scriptlets : 

      <% code %>  :� Inserted verbatim into the servlet�s _jspService method (called by

service)

  ï¿½ Declarations  :

      <%! code %>  :- Inserted verbatim into the body of the servlet class, outside of any

existing methods.

  ï¿½ Directive :

      <%@ directive %>  :- To use \"import\" statements in JSPs.


How do I include static files within a JSP page?

We can include static files within a JSP page using the include directive :


< % @ include file=\"top.html\" % > 



How can I implement a thread-safe JSP page?

To make your JSPs thread-safe, you hace to implement the SingleThreadModel interface.


This can be done by using page directive with isThreadSafe attribute by setting it to false:


<%@ page isThreadSafe=\"false\" %>


What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?

The getRequestDispatcher() can take a relative path while getRequestDispatcher() take relative to the current context\'s root.


Example :  


With ServletRequest- 

request.getRequestDispatcher(\"./jsp/jsppage.jsp\") :- evaluated relative to the path of the request  

request.getRequestDispatcher(\"/jsp/jsppage.jsp\")  :- evaluated relative to the root are all valid.


With ServletContext only

context.getRequestDispatcher(\"/jsp/jsppage.jsp\") is valid.


What are context initialization parameters?

Context initialization parameters are defined in the Deployment descriptor an accessible to all the servlets in the application. You can use context initialization parameters to specify the information that is dynamically change. You can also use these to specify the URL of the database.


<context-param>  

<param-name>webmaster</param-name>  

<param-value>jalees786@gmail.com</param-value>  </context-param> 

What is a Expression?

Expression in JSP is used to write the output on the stream. It has the following form :


<%= Java Expression %>


The Java expression is evaluated, converted to a string, and inserted in the page. This evaluation is performed at run-time and thus has full access to information about the request. For example, the following shows the date/time that the page was requested:


Current time is : <%= new java.util.Date() %>


What is a Declaration?

You must declare the variable or method before you use it in the JSP page. The Declaration is a JSP element use to declare the variable or methods that you can use in Java code later in the JSP page.


JSP Declaration :

  <%! code %>  :- Code is inserted in body of servlet class, outside of service method. 


Example : The declaration must be valid in the scripting language used in the JSP file.


<%! int i = 0; %>

<%! int a, b, c; %>

What is a Scriptlet?

Scriptlet is a JSP element. It contains the java code enclosed within <% and %>. JSP Engine places these code in the _jspService() method.

Syntax of JSP Scriptles are:


  <%

  //java codes

   %>


Example:

<HTML>

<BODY>

<%

    String userName=null;

    userName=request.getParameter(\"userName\");

    System.out.println( \"Current Date is:\" );

    java.util.Date date = new java.util.Date();

%>

    Hello <%= userName %> ! <br> 

    The time is now :<%= date %>

</BODY>

</HTML>

What are the implicit objects?

Web container provides developer to access some objects instantiated by container and available to all the jsp pages. These objects are called implicit objects because they are automatically instantiated. Within each JSP application is the complete set of implicit objects.


There are nine implicit objects in JSP. 

1. pageContext 

2. session 

3. request 

4. response 

5. exception 

6. out 

7. application 

8. config 

9. page 

What\'s the difference between forward and sendRedirect?

When using request.forward(), request is forwarded to the another resource specified in the forward() parameter. Whereas response.sendRedirect() causes the web container to return to the browser indicating that a new URL should be requested. The browser issues a completely new request any object that are stored as request attributes before the redirect occurs will be lost.

What are the different scopes available ?

Scope tells accessibility of the object in the web application. JSP has the following scopes :   

     1. page   

     2. request   

     3. session   

     4. application


Is JSP extensible ?

Yes! JSP is extensible. PolyJsp is an extensible JSP  implementation designed to support multiple scripting languages  and multiple JSP versions. PolyJsp is completely based on XML and XSL and supports Java, Javascript and WebL  as scripting languages.

Except JSP directives (<%@ %>), declarations (<% %>), scriptlets (<% %>) and expressions (<%= %>),  PolyJsp introduces a few (optional) extensions to JSP :


    * A <%@ version=\"...\" > directive

      Useful to instruct the parser to use a version other than the default (currently 0.92)

    * A <%@ contenttype=\"...\"> directive

      Useful for cases in which the expected output MIME type is other than text/html

    * A <header name=\"...\" value=\"...\">

      Useful to set response headers. Example: set expires to control browser chaching 

What is the difference between <%@ include ...> (directive include) and ?

The include directive :- 

<%@ include file=\"fileName\" %>

is static and processed at the time when the JSP page is translated into its equivalent servlet. The file included in the page at the time translation and compiled file also contain the included file code. This directive is normally used for including static resources only - like, banner, header, footer, etc. If you make some changes in the included file then it will not affect those files which had included this file.


The include action :- 

<jsp:include page=\"relativeURL\" />

is dynamic and processed at runtime. This will simply make a function call at run time to the included file. This action allows additional parameters to be passed via <jsp:param> child element of this include action element. If you make some changes in the included file then it will also affect those files which had included this file.

Can I just abort processing a JSP?

Yes! We can abort the processing of JSP because at the end every JSP file turned into a servlet and we can put a return statement into the service method, so we can put a return statement into JSP code, i.e. we can put <% return; %> into the JSP file.

What are the parameters for service method ?

Most of the servlets are written by extending the HttpServlet class and override the HttpServlet\'s service() method. This method takes two parameters :

   * HttpServletRequest, and 

   * HttpServletResponse.

HttpServlet class extends the GenericServlet and override the service() method of GenericServlet class, which takes two parameters :

   * ServletRequest, and 

   * ServletResponse.


HttpServletRequest interface extends the ServletRequest interface and HttpServletResponse extends ServletResponse interface.

How do I prevent the output of my JSP or Servlet pages from being cached by the browser?

By setting HTTP header attributes you can prevent the output of my JSP or Servlet pages from being cached by the browser. You can do this by the following code : 


<%

response.setHeader(\"Cache-Control\",\"no-cache\"); //HTTP 1.1

response.setHeader(\"Pragma\",\"no-cache\"); //HTTP 1.0

response.setDateHeader (\"Expires\", 0); //prevents caching at the proxy server

%>

How to refer the \"this\" variable within a JSP page?

Under JSP 1.0, the \"page\" implicit object page is equivalent to \"this\", and returns a reference to the servlet generated by the JSP page. 

Can we implement an interface in JSP ?

No! In JSP we can\'t implement the interface. However we can use the class in the JSP file which has implemented the interface.

How do I use a scriptlet to initialize a newly instantiated bean?

The <jsp:useBean> may also optionally have a body. You can make use of a JSP expression within the <jsp:setProperty> action in the body of <jsp:useBean>. 


For Example :


<jsp:useBean id=\"foo\" class=\"Bar.Foo\" >


<jsp:setProperty name=\"foo\" property=\"today\" value=\"<%=java.text.DateFormat.getDateInstance().format(new java.util.Date()) %>\" / >

</jsp:useBean > 

What are JSP Actions?

JSP Actions are XML tags that are executed at run time. These tags transfer the control between the pages and also use the server side beans :

Some JSP Actions are : 

  * jsp:include,

  * jsp:useBean,

  * jsp:setProperty,

  * jsp:getProperty,

  * jsp:forward,

  * jsp:plugin.

What is the difference between ServletContext and ServletConfig?

ServletContext and ServletConfig are declared in the deployment descriptor. ServletConfig is one per servlet and can be accessed only within that specific servlet. ServletContext is one per web application and accessible to all the servlet in the web application.

What is a Hidden Comment?

A hidden comment is a JSP comment that is not sent to the client. Syntax :


  <%-- Hidden comment --%>

How to pass information from JSP to included JSP?

You can pass information from JSP to the included JSP using the <jsp:param> in the body of <jsp:include> action. 

Example :


<jsp:include page=\"relativeURL\">

      <jsp:param name=\"parameterName\" value=\"parameterValue\"/> 

</jsp:include>


How do you pass data (including JavaBeans) to a JSP from a servlet?

You can pass information to a JSP page from the servlet. Using setAttribut() on request object in the servlet and forward it as follows : 

  

RequestDispatcher rd = 

getServletContext().getRequestDispatcher(\"test.jsp\");

rd.forward(request,response);

How can I set a cookie?

You can set the cookie by setValue() method on cookie object.

Example :

cookie.setValue(\"My own value\");

How will you delete a cookie?

To delete cookie from servlet, get the cookie from the request object and use setMaxAge(0) and then add the cookie to the response object. 


To delete cookie from JSP, use the following scriptlet:


<%

     Cookie killMyCookie = new Cookie(\"mycookie\", null);

     killMyCookie.setMaxAge(0);

     killMyCookie.setPath(\"/\");

     response.addCookie(killMyCookie);

%>


What JSP lifecycle methods we can override?

JSP lifecycle methodsn :


  * JspInit()

  * _JspService()

  * JspDestroy()


You can override the jspInit() and jspDestroy() methods but you can\'t override the _jspService() method within a JSP page. The jspInit() can be useful for allocating resources like database connections, network connections, etc. The jspDestroy() method can be useful to free up the resources.

How will you include a static file in a JSP page?

You can include a static file in a JSP page by using include directive :


<%@ include file=\"relativeURL\" %>

How you can perform browser redirection?

You can perform browser redirection using sendRedirect() method on response object in the servlet. Example :

response.sendRedirect(\"http://www.r4r.co.in/path/error.html\");


You can also physically alter the Location HTTP header attribute, as shown below:

<%

response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);

String newLocn = \"/newpath/index.html\";

response.setHeader(\"Location\",newLocn);

%>


Can we use ServletOutputStream object from a JSP page?

We can\'t use ServletOutputStream object from a JSP page. You can use JspWriter object. A JSPWriter can be viewed as a buffered version of the stream object returned by response.getWriter(). A page author can always disable the default buffering for any page using a page directive as: <%@ page buffer=\"none\" %>.


How can I invoke a JSP error page from a servlet?

Yes, You can invoke JSP error page from a servlet by passing the exception object as a javax.servlet.jsp.jspException request attribute.


Example : 


protected void sendErrorRedirect(HttpServletRequest request, 

HttpServletResponse response, String errorPageURL, Throwable e) throws

ServletException, IOException {

request.setAttribute (\"javax.servlet.jsp.jspException\", e);

getServletConfig().getServletContext().

getRequestDispatcher(errorPageURL).forward(request, response);

}

public void doPost(HttpServletRequest request, HttpServletResponse response)

{

try {

// Code that might cause exception

} catch (Exception ex) {

try {

sendErrorRedirect(request,response,\"/jsp/ErrorPage.jsp\",ex);

} catch (Exception e) {

e.printStackTrace();

}

}

}


How can I enable session tracking for JSP pages if the browser has disabled cookies?

URL rewriting is another way to track the session if the browser has disabled the cookies. URL rewriting essentially includes the session ID within the link itself as a name/value pair. 

We have two methods for this purpose :  response.encodeURL() associates a session ID with a given URL, and if you are using redirection, response.encodeRedirectURL() can be used by giving the redirected URL as input. Both these methods determines whether the cookies are enabled or not. If cookies are enabled then the input URL will returned unchanged since the session ID will be persisted as a cookie, otherwise append the session ID for each and every link that is part of your servlet response. 


For Example :


hello1.jsp

<%@ page session=\"true\" %>

<%

Integer num = new Integer(100);

session.putValue(\"num\",num);

String url =response.encodeURL(\"hello2.jsp\");

%>

<a href=\'<%=url%?phpMyAdmin=70ac9566533a2665b6597346aab7f985&phpMyAdmin=f43d4e0b88acea2d2a393515f6bf38f2>\'>hello2.jsp</a>


hello2.jsp

<%@ page session=\"true\" %>

<%

Integer i= (Integer )session.getValue(\"num\");

out.println(\"Num value in session is \" + i.intValue());

%> 

  

How can you declare methods in your JSP page?

Mehods in the JSP Page can be declared using the JSP \"declaration\" elemenet.

Example :


<%!

public String  getInfo(HttpServletRequest req){

String n=req.getParameter(\"name\");

String d=req.getParameter(\"designation\");

return n+\" is a \"+d;

}

%>


<%

out.println(getInfo(request));

%>

How can we set the inactivity period on a per-session basis?

A default inactivity lease period for all sessions is set within your JSPengine admin screen or associated properties file. However, if your JSP engine supports the Servlet 2.1 API, you can manage the inactivity lease period on a per-session basis. This is done by invoking the HttpSession.setMaxInactiveInterval() method, right after the session has been created. For example:

<%

session.setMaxInactiveInterval(180);

%>


would reset the inactivity period for this session to 3 minutes. The inactivity interval is set in seconds.

How do you pass an init parameter to a JSP?

You can pass the init parameters into your JSP file by decaring them into your deployment descriptor web.xml file.


<servlet>  

   <servlet-name>My Page</servlet-name>

   <jsp-file>/mypage.jsp</jsp-file>  

   <init-param>  

      <param-name>email</param-name>  

      <param-value>jalees786@gmail.com</param-value) </init-param>

</servlet>


<servlet-mapping> 

   <servlet-name>My Page</servlet-name>

   <url-pattern>/foo</url-pattern> 

</servlet-mapping> 


You can access init parameters into your JSP file using the following code :


<% 

String email = getServletConfig().getInitParameter(\"email\");

%>

How can my application get to know when a HttpSession is removed?

You need to define a class, say SessionRemovedNotifier, that implements javax.servlet.http.HttpSessionBindingListener interface. HttpSessionBindingListener interface have two methods : valueBound() and valueUnbound(). Create a SessionRemovedNotifier object and add it to the user session. When the session is removed, SessionRemovedNotifier.valueUnbound() will be called by the web container. You can implement valueUnbound() to do whatever you want. 

How many cookies can one set in the response object of the servlet? Also, are there any restrictions on the size of cookies?

A cookie has a maximum size of 4K, and no domain can have more than 20 cookies.

When a session object gets added or removed to the session, which event will get notified ?

When an object is added or removed from a session, the container checks the interfaces implemented by the object. If the object implements the HttpSessionBindingListener, the container calls the matching notification method. To receive this notification, your object must implement the javax.http.HttpSessionBindingListener interface.

What is URL Encoding and URL Decoding ?

Some characters are not valid in URLs like & can\'t be placed in a URL query string without changing the meaning of that query string.


These problems can be be fixed by \'escaping\' them. This process involves scanning the text for those characters, and replacing them with a special character-code that browsers can interpret as the correct symbol, without actually using that symbol in your URL.


For example, the escaped character code for \'=\' is \'%3d\'. 

What is the difference between an applet and a servlet?

Applets are client side java program that are dynamically downloaded over the internet and executed by browser. Servlets are server side program runs on the server. When a request come to server for the specific servlet, then servlet handles the client request, and send response back to the client. 

Servlet doesn\'t have GUI , while applet have GUI. Applet are very heavy to handle as compared to servlet


What are the different web servers available name few of them?

The different web servers are :

  * Apache Tomcat

  * Apple WebObjects

  * ATG Dynamo

  * BEA WebLogic

  * Borland Enterprise Server

  * Caucho Resin

  * Fujitsu Siemens Computers BeanTransactions

  * Gefion Software LiteWebServer

  * IBM Websphere

  * Macromedia JRun Server

  * Persistence Power Tier for J2EE

  * Sybase EAServer

  * Sun Microsystems Sun Java System Application Server

What are the different types of ServletEngines?

A servlet engine handles the client requests for servlets, JSP files, and other types of server-side include coding. The servlet engine creates servlet instances, loads and unloads servlets, manage the servlet life cycle, creates and manages request and response objects, and performs other tasks for managing servlets effectively. 

If the server application is written as a Java Servlet, it will need a place to execute, and this place is typically called a Servlet Engine. When you move on to Enterprise JavaBeans, you move into the application server space. An Application Server is any server that supplies additional functionality related to enterprise computing -- for instance, load balancing, database access classes, transaction processing, messaging, and so on. 

EJB Application Servers provide an EJB container, which is the environment that beans will execute in, and this container will manage transactions, thread pools, and other issues as necessary. 

What is a Session Id?

A Session ID is a unique identifier given by the server to the specific client to support communicatio between for a time period. The session ID can be stored as a cookie, form field, or URL (Uniform Resource Locator). Some Web servers generate session IDs by simply incrementing static numbers. However, most servers use algorithms that involve more complex methods, such as factoring in the date and time of the visit along with other variables defined by the server administrator.

What is the use of setComment and getComment methods in Cookies ?

A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number. 


The setComment(java.lang.String purpose) method Specifies a comment that describes a cookie\'s purpose.The getComment() method returns the comment describing the purpose of the cookie, or null if the cookie has no comment.

Why we are used setMaxAge() and getMaxAge() in Cookies ?

The \"public void setMaxAge(int expiry)\" method sets the maximum age of the cookie. After the specified time the cookie will be deleted.


The \"public int getMaxAge()\" method will return the maximum specified age of the cookie.

What is the use of setSecure() and getSecure() in Cookies ?

The setSecure(boolean flag) method indicates to the browser whether the cookie should only be sent using a secure protocol, such as HTTPS or SSL.

The getSecure() method returns true if the browser is sending cookies only over a secure protocol, or false if the browser can send cookies using any protocol.

Is HTML page a web component?

No! Html pages are not web component, even the server-side utility classes are not considered web components. Static HTML pages and applets are bundled with web components during application assembly, but are not considered web components by the J2EE specification.

What is the container?

The Web container provides the runtime environment through components that provide naming context and life cycle management, security and concurrency control. A web container provides the same services as a JSP container as well as a federated view of the Java EE. Apache Tomcat is a web container and an implementation of the Java Servlet and JavaServer Pages technologies.

What is deployment descriptor?

Deployment descriptor is a configuration file named web.xml that specifies all the pieces of a deployment. It allows us to create and manipulate the structure of the web application. Deployment descriptor describes how a web application or enterprise application should be deployed. For web applications, the deployment descriptor must be called web.xml and must reside in a WEB-INF subdirectory at the web application root. Deployment descriptor allows us to modify the structure of the web application without touching the source code.

How can I print the stack trace of an exception from a JSP page?

To print the stack trace of an exception from a JSP page you will have to use a PrintWriter object instead of usnig JSP out implicit variable.


<%

out.println(\"<!--\");

StringWriter sw = new StringWriter();

PrintWriter pw = new PrintWriter(sw);

exception.printStackTrace(pw);

out.print(sw);

sw.close();

pw.close();

out.println(\"-->\");

%>


In the above code you have import=\"java.io.* package.


Do objects stored in a HTTP Session need to be serializable? Or can it store any object?

It\'s important to make sure that all objects placed in the session can be serialized if you are building a distributed applicatoin. If you implement Serializable in your code now, you won\'t have to go back and do it later. 

What is the differecnce between JspWriter and PrintWriter?

JspWriter is a buffered version of the PrintWriter. JspWriter also differs from a PrintWriter by throwing java.io.IOException, which a PrintWriter does not. If the page is not buffered, output written to this JspWriter object will be written through to the PrintWriter directly, which will be created if necessary by invoking the getWriter() method on the response object. But if the page is buffered, the PrintWriter object will not be created until the buffer is flushed and operations like setContentType() are legal. Since this flexibility simplifies programming substantially, buffering is the default for JSP pages.

How can you implement singleton pattern in servlets ?

Singleton is a useful Design Pattern for allowing only one instance of your class. you can implement singleton pattern in servlets by using using Servlet init() and <load-on-startup> in the deployment descriptor.</load-on-startup>

What is the difference between an application server and a web server?

A Web server handles the HTTP protocol. When the Web server receives an HTTP request, it responds with an HTTP response, such as sending back an HTML page. it doesnt do any operations. that means franckly seaking it can serve only html files, if u ask for ASP/Servlets/Jsp page then the request will be redirected to the particular engine(incase of ASP-ASPEngine, Servlet-ServletEngine, no idea abt JSP but it should be like this only) then the engine will process the file then it gives a htm output that will be returned to the client thats what abt the webserver.

An application server exposes business logic to client applications through various protocols. While a Web server mainly deals with sending HTML for display in a Web browser, an application server provides access to business logic for use by client application programs. The application server exposes the business logic through a component API, such as the EJB (Enterprise JavaBean) component model found on J2EE (Java 2 Platform, Enterprise Edition) application servers. Application Server usually refers to a server that is able to handle the entire J2EE specification (JSP, Servlets, EJBs, etc). Most Application Servers also contain web servers.

Can we implement Runnable interface from within our servlet?

No! Servlet do not implement reunnable interface. Servlets are not multithreaded. However they run in a multithreaded environment under the control of web container.

What is Web application ?

Web applications including those built with Java technologies such as JavaServer Pages and servlets, as well as those built with non-Java technologies such as CGI and Perl. Web application is the type of Application , Which is written for the Internet.

What is Web component ?

A Web Component is bassically a tyoe of component that provides services in response to requests, either a servlet or a JSP page.

What is RequestPocessor class? How will you create your own RequestPocessor?

Can you test a JSP page using Junit?