JSP Interview Questions

Prev Tutorial Next Tutorial

JSP Interview Questions

jsp interview questions

JSP Interview Question for Freshers

What is JSP ?

JSP technology is used to create dynamic web application same like Servlet technology. It is another web technology given by Sun MicroSystem for the development of dynamic web pages on the client browser. It provides a tag based approach to develop java web components.

What is basis aim of jsp ?

The basis aim of JSP technology is to design any java based web application in easy way.

Why Use JSP ?

The first technology given for the development of web application is CGI. In CGI have some drawback, So Sun MicroSystem develop a new technology is servlet. But working with Servlet Sun MicroSystem identify some problem, Servlet technology need in depth java code and Servlet is failed to attract the programmer.

To overcome the problem with Servlet technology we use jsp technology.

Why jsp is called as a pages ?

A JSP is called as page but not program because a JSP contains totally tags.

Why we not configure JSP file in web.xml ?

Configuring a JSP into a web.xml file is optional because JSP is a public file to the web application.

Why JSP is called a public file and servlet called private file ?

A JSP called a public file and servlet is called a private file of the web application. Because JSP files stored in root directory of the web application and Servlet class file stored in sub directory of the web application. Because JSP is the public file, we can directly send a request from a browser by using its file name.

When we need Servlet ?

For hug request processing logic with less response generation logic we need Servlet

When we use JSP ?

With less request processing logic with more response generation logic we need JSP.

What are Problem with Servlet

If any changes in static html code of Servlet, the entire Servlet need recompilation, redeployment, needs server restart.

Any modification in Servlet needs recompilation because both request processing logic and response generation logic are tight coupled.

Why jsp is browser and j2ee server independent ?

JSP tags will process and execute by the server side web container, So that these are browser independent and j2ee server independent.

Why no need to configuring a JSP into a web.xml file ?

Configuring a JSP into a web.xml file is optional because JSP is a public file to the web application.

What is difference between jsp tag and html tag ?

A JSP page contains both html tags and JSP tags. Html tags will produce static output and JSP tags will produced dynamic output. Because of JSP tags we called as JSP is dynamic web page.

Difference Between Servlet and JSP

1Servlet is faster than jspJSP is slower than Servlet because it first translate into java code then compile.
2In Servlet, if we modify the code then we need recompilation, reloading, restarting the server> It means it is time consuming process.In JSP, if we do any modifications then just we need to click on refresh button and recompilation, reloading, restart the server is not required.
3Servlet is a java code.JSP is tag based approach.
4In Servlet, there is no such method for running JavaScript at client side.In JSP, we can use the client side validations using running the JavaScript at client side.
5To run a Servlet you have to make an entry of Servlet mapping into the deployment descriptor file i.e. web.xml file externally.For running a JSP there is no need to make an entry of Servlet mapping into the web.xml file externally, you may or not make an entry for JSP file as welcome file list.
6Coding of Servlet is harden than jsp.Coding of jsp is easier than Servlet because it is tag based.
7In MVC pattern, Servlet plays a controller role.In MVC pattern, JSP is used for showing output data i.e. in MVC it is a view.
8Servlet accept all protocol request.JSP will accept only http protocol request.
9In Servlet, aervice() method need to override.In JSP no need to override service() method.
10In Servlet, by default session management is not enabled we need to enable explicitly.In JSP, session management is automatically enabled.
11In Servlet we do not have implicit object. It means if we want to use an object then we need to get object explicitly form the servlet.In JSP, we have implicit object support.
12In Servlet, we need to implement business logic, presentation logic combined.In JSP, we can separate the business logic from the presentation logic by uses javaBean technology.
13In Servlet, all package must be imported on top of the servlet.In JSP, package imported anywhere top, middle and bottom.

Difference between life cycle init() of servlet and life cycle method of init() of jsp.

Servlet init() contains ServletConfig object as a parameter but JspInit() does not contain any parameter..

config object is accessible in Servlet init(), but it is not accessible in JspInit().

Servlet init() throws ServletException and JspInit() does not throw any exception.

Why JSP Comment called hidden Comment

JSP Comments are not visible on any phase of JSP program execution due to this they are called hidden Comment

Difference Between JSP and HTML

Html is a Client side Technology and JSP is a Server side Technology. Some other differences are given below;

1Html is given by w3c (World Wide Web Consortium).JSP is given by SunMicro System.
2Html generated static web pages.JSP generated dynamic web pages.
3It do not allow to place java code inside Html pages.JSP allows to place java code inside JSP pages.
4It is Client side technologyIt is a Server side technology.
5Need Html Interpreter to execute these code.Need JSP container to execute jsp code.
6It does not allow to place custom tag or third party tag.It allow to place custom tag or third party tag.

Why JSP suppor all the feature of Servlet ?

JSP have all the features of Servlet because it is internally Servlet.

Difference between get and post method.

Http protocol mostly use either get() or post() methos to transfer the request.

Get methodPost method
1Request sends the request parameter as query string appended at the end of the request.Post request send the request parameters as part of the http request body.
2Get method is visible to every one (It will be displayed in the address bar of browser ).Post method variables are not displayed in the URL.
3Restriction on form data, only ASCII characters allowed.No Restriction on form data, Binary data is also allowed.
4Get methods have maximum size is 2000 character.Post methods have maximum size is 8 mb.
5Restriction on form length, So URL length is restrictedNo restriction on form data.
6Remain in browser history.Never remain the browser history.

What is JSP life Cycle ?

A JSP life cycle can be defined as the entire process from its creation till the destruction which is similar to a Servlet life cycle with an additional step which is required to translate a JSP into Servlet. Read more.........

Give Life cycle of a JSP Page

  • Translation of JSP Page to Servlet
  • Compilation of JSP Page
  • Classloading (class file is loaded by the classloader)
  • Instantiation (Object of the Generated Servlet is created).
  • Initialization ( jspInit() method is invoked by the container).
  • Reqeust processing ( _jspService() method is invoked by the container).
  • Destroy ( jspDestroy() method is invoked by the container).

What are Life cycle method of JSP ?

  • jspInit()
  • _jspService()
  • jspDestroy()

You can override _jspService() method ?

No, we can not override _jspService() method but we can override jspInti() and jspDestroy().

How to inform programer which method can not override ?

To inform the programmer that you should not override the service() method the method name is started with '_' symbol.

What is Scripting Element in JSP ?

In JSP, java code can be written inside the jsp page using the scriptlet tag. JSP Scripting element are written inside <% %> tags. These code inside <% %> tags are processed by the JSP engine during translation of the JSP page. Read more.......

What is JSP Declaration Tag ?

This is used to declare variable and methods in jsp page will be translate and define as class scope declaration in .java file. Read more.......

What is JSP Expression Tag ?

Expression tag is used, to find the result of the given expression and send that result back to the client browser. In other words; These are used to show or express the result or response on browser. We can use this as a display result of variable and invoking method. Read more.......

What is JSP Scriptlet Tag ?

It use to define or insert java code in a jsp. Every java statement should followed by semicolon (;). It will be place into jspService() method. Read more.......

What is Request Implicit Object ?

The JSP request is an implicit object of type HttpServletRequest i.e. created for each jsp request by the web container. It can be used to get request information such as parameter, header information, remote address, server name, server port, content type, character encoding etc. Read more.........

What is Response Implicit Object ?

In JSP, response is an implicit object of type HttpServletResponse. The instance of HttpServletResponse is created by the web container for each jsp request. Read more......

What is JSP Directive Elements ?

The directive elements are used to do page related operation during page translation time. JSP supports 3 types of directive elements, they are;.

  • Page directive
  • Include directive
  • Taglib directive

What is Include Directive ?

It is used to include some other pages into the JSP document, it may be jsp file, html file or text file. This is known as static include because the target page is located and included at the time of page compilation.

Why use Include Directive in jsp ?

For Code Re-usability

What is Page Directive ?

The page directive defines attributes that apply to an entire JSP page. This element is used to define default of explicit operation to the jsp. Read more..........

Taglib Directive ?

This is used to use custom tags in JSP page, here the custom tag may be user defined ot JSTL tag or strust, JSF,..... etc. Read more..........

Difference between Include Directive and Include Action

Include DirectiveInclude Action
1In Include directive, the code of one jsp page is inserted into another jsp. It is called as compile time or static including.Include Action, the response of one page will be inserted into another page. It is called as run-time or dynamic including.
2In Include directive, for both source and destination pages, only a single Servlet will be generated internally so number of Servlet object are reduced.In Include action, individually Servlet are generated for each jsp page. So it increases the number of servlet object.
3In Include directive, the destination must be jsp page only.In Include action, the destination resource can be a jsp or Servlet or html.
4In jsp include directive, we have both html and xml syntax for the tag.In include action, we have only xml syntax but there is one html syntax.
5<%@include file=" "%><%JSP:include page=" "%>
6In include directive, the file must be available in the within some application.In include action the page may exits either within same application or another web application of server.

Prev Tutorial Next Tutorial

Google Advertisements
Download Projects

Google Adsense Advertisements

Buy 3 Year Old Domain, Tutorialday.com, SeosmoTools.com @$200

Buy This Ad Space @$50 per Month, Ad Size 300X250 Contact on: hitesh.xc@gmail.com WhatsApp no. 8882538826

Yahoo Advertisements