trainingtrains Logo

91-9990449935

 0120-4256464

Jsp Interview questions

There is a list of 25 jsp interview questions for freshers and professionals. If you know any jsp interview question that has not been included here, post your question in the Ask Question section.


1)What is JSP?

Java Server Pages technology (JSP) is used to create dynamic web page. It is an extension to the servlet technology. A JSP page is internally converted into servlet.

more details...

2) What are the life-cycle methods for a jsp?

MethodDescription
public void jspInit() It is invoked only once, same as init method of servlet.
public void _jspService(ServletRequest request,ServletResponse)throws ServletException,IOException It is invoked at each request, same as service() method of servlet.
public void jspDestroy()It is invoked only once, same as destroy() method of servlet.

3)What is difference between hide comment and output comment?

The jsp comment is called hide comment whereas html comment is called output comment. If user views the source of the page, the jsp comment will not be shown whereas html comment will be shown.


4)What are the JSP implicit objects ?

JSP provides 9 implicit objects by default. They are as follows:

ObjectType
1) outJspWriter
2) requestHttpServletRequest
3) responseHttpServletResponse
4) configServletConfig
5) sessionHttpSession
6) applicationServletContext
7) pageContextPageContext
8) pageObject
9) exceptionThrowable
more details...

5)What is difference between include directive and include action?

include directiveinclude action
1) The include directive includes the content at page translation time.1) The include action includes the content at request time.
2) The include directive includes the original content of the page so page size increases at runtime.2) The include action doesn't include the original content rather invokes the include() method of Vendor provided class.
3) It's better for static pages.3) It's better for dynamic pages.

6) Is JSP technology extensible?

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


7) How can I implement a thread-safe JSP page? What are the advantages and Disadvantages of using it?

You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive <%@ page isThreadSafe="false" %> within your JSP page.


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

(OR) How to disable caching on back button of the browser?


9) How can we handle the exceptions in JSP ?

There are two ways to perform exception handling, one is by the errorPage element of page directive, and second is by the error-page element of web.xml file.

more details...

10) What are the two ways to include the result of another page. ?

There are two ways to include the result of another page:


11) How can we forward the request from jsp page to the servlet ?

Yes ofcourse! With the help of forward action tag, but we need to give the url-pattern of the servlet.

forward action tag

12) Can we use the exception implicit object in any jsp page ?

No. The exception implicit object can only be used in the error page which defines it with the isErrorPage attribute of page directive.

more details...

13) How is JSP used in the MVC model?

JSP is usually used for presentation in the MVC pattern (Model View Controller ) i.e. it plays the role of the view. The controller deals with calling the model and the business classes which in turn get the data, this data is then presented to the JSP for rendering on to the client.

forward action tag

14) What are context initialization parameters?

Context initialization parameters are specified by the <context-param> in the web.xml file, these are initialization parameter for the whole application and not specific to any servlet or JSP.

more details...

15) What are the different scope values for the <jsp:useBean> tag?

There are 4 values:

  1. page
  2. request
  3. session
  4. application
more details...

16)What is the difference between ServletContext and PageContext?-

ServletContext gives the information about the container whereas PageContext gives the information about the Request.


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

request.getRequestDispatcher(path) is used in order to create it we need to give the relative path of the resource whereas context.getRequestDispatcher(path) in order to create it we need to give the absolute path of the resource.


18) What is EL in JSP?

The Expression Language(EL) is used in JSP to simplify the accessibility of objects. It provides many objects that can be used directly like param, requestScope, sessionScope, applicationScope, request, session etc.


19)What is basic differences between the JSP custom tags and java beans?

  • Custom tags can manipulate JSP content whereas beans cannot.
  • Complex operations can be reduced to a significantly simpler form with custom tags than with beans.
  • Custom tags require quite a bit more work to set up than do beans.
  • Custom tags are available only in JSP 1.1 and later, but beans can be used in all JSP 1.x versions.

20) Can an interface be implemented in the jsp file ?

No.


21) What is JSTL?

JSP Standard Tag Library is library of predefined tags that ease the development of JSP.

more details...

22) How many tags are provided in JSTL?

There are 5 type of JSTL tags.

  1. core tags
  2. sql tags
  3. xml tags
  4. internationalization tags
  5. functions tags
more details...

23) Which directive is used in jsp custom tag?

The jsp taglib directive.


24) What are the 3 tags used in JSP bean development?

  1. jsp:useBean
  2. jsp:setProperty
  3. jsp:getProperty
more details...

25) How to disable session in JSP?