Tolal:67 Click:
1
2 3 4
JSP Interview Questions And Answers
Page 1
Ques: 1 Can you test a JSP page using Junit?
Ques: 2 What is RequestPocessor class? How will you create your own RequestPocessor?
Ques: 3 Can we implement Runnable interface from within our servlet?
Ans:
No! Servlet do not implement reunnable interface. Servlets are not multithreaded. However they run in a multithreaded environment under the control of web container.
Ans:
yes
Ques: 4 What is the difference between an application server and a web server?
Ans:
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.
Ans:
Application Server contains Servlet container, JSP container and EJB container while Web Server contains Servlet container and JSP container only.
Ques: 5 How can you implement singleton pattern in servlets ?
Ans:
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.
Ques: 6 What is the differecnce between JspWriter and PrintWriter?
Ans:
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.
Ques: 7 Do objects stored in a HTTP Session need to be serializable? Or can it store any object?
Ans:
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.
Ques: 8 How can I print the stack trace of an exception from a JSP page?
Ans:
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.
Ques: 9 What is deployment descriptor?
Ans:
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.
Ques: 10 What is the container?
Ans:
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.
Ques: 11 Is HTML page a web component?
Ans:
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.
Ques: 12 What is the use of setSecure() and getSecure() in Cookies ?
Ans:
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.
Ques: 13 Why we are used setMaxAge() and getMaxAge() in Cookies ?
Ans:
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.
Ques: 14 What is the use of setComment and getComment methods in Cookies ?
Ans:
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.
Ques: 15 What is a Session Id?
Ans:
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.
Ques: 16 What are the different types of ServletEngines?
Ans:
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.
Ques: 17 What are the different web servers available name few of them?
Ans:
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
Ques: 18 What is the difference between an applet and a servlet?
Ans:
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
Ques: 19 What is URL Encoding and URL Decoding ?
Ans:
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'.
Ques: 20 When a session object gets added or removed to the session, which event will get notified ?
Ans:
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.
Goto Page:
1
2 3 4
JSP Objective
JSP Objective Questions And Answers
JSP Interview Questions And Answers
JSP Subjective Questions And Answers
R4R,JSP Objective, JSP Subjective, JSP Interview Questions And Answers,JSP,JSP Interview,JSP Questions ,JSP Answers