Pr.Pg Next Pg

JSP Interview Questions and Answers Part 1


1.What is a JSP and what is it used for?

  • Java Server Pages(JSP) is a technology that helps software developers to create dynamically generated web pages based on HTML, XML, or other document types. Released in 1999 by Sun Microsystems.

  • JSP is similar to PHP, but it uses the Java programming language.

  • JSP helps the developer to insert java code inside HTML by making use of JSP tags most commonly scriptlet starts with <% and ends with %> which is very useful for generating dynamic contains on a web page.

  • JSP are direct extension of Java servlets and provide a way to separate contents generation from content presentation. The JSP engine is just another servlets that is mapped to the extension *.jsp

  • JavaServer Pages inherit the concepts of Applications, ServletContexts, Sessions, Requests, and Responses from the Java Servlets API and offer the same portability, performance, and scalability as servlets.

  • Jsp tags can be use for various purpose such as retrieving data from database, registering user preferences, accessing JavaBeans components, passing control between pages and sharing information between requests pages etc.

  • JSP are deployed and run on Servlet container such as Apache Tomcat or Blazix.

  • JSP pages are saved to *.jsp files. A JSP compiler is used in the background to generate a Servlet from the JSP page.


2.What are the two kinds of comments in JSP and what's the difference between them ?

  • <%-- JSP Comment --%>

  • <!-- HTML Comment -->


3.What is JSP technology?

  • Java Server Page is a standard Java extension that is defined on top of the servlet Extensions.

  • The goal of JSP is the simplified creation and management of dynamic Web pages.

  • JSPs are secure, platform-independent, and best of all, make use of Java as a server-side scripting language.


4.What is JSP page?

  • A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format such as HTML, SVG, WML, and XML, and JSP elements, which construct dynamic content.


5.What are the implicit objects?

  • Implicit objects are objects that are created by the web container and contain information related to a particular request, page, or application.

  • They are:request response pageContext session application out config page exception


6.How many JSP scripting elements and what are they?

  • There are three scripting language elements:

  • declarations

  • scriptlets

  • expressions


7.Why are JSP pages the preferred API for creating a web-based client program?

  • Because no plug-ins or security policy files are needed on the client systems(applet does).

  • Also, JSP pages enable cleaner and more module application design because they provide a way to separate applications programming from web page design.

  • This means personnel involved in web page design do not need to understand Java programming language syntax to do their jobs.


8.Is JSP technology extensible?

  • YES.

  • JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries.



9.Can we use the constructor, instead of init(), to initialize servlet?

  • Yes , of course you can use the constructor instead of init(). There’s nothing to stop you.

  • But you shouldn’t. 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 constructur 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.


10.How can a servlet refresh automatically if some new data has entered the database?

  • You can use a client-side Refresh or Server Push.

Pr.Pg border                                              Next Pg