JSP Interview Questions & Answers

Que1: What is JSP?
  1. JSP is an abbreviation of Java Server Pages
  2. It is use to create dynamic web application.
  3. JSP is an extension of servlet because all the features of servlet are available in JSP, In addition to this, it also have some additional features like expression language, predefined tags, implicit objects, custom tags etc.
  4. It is mainly use for presentation logic but we can also use it for presentation and business logic.
  5. It is easy to maintain because we can easily separate our business logic and presentation logic.
  6. Fast development: if JSP page is modified, we don't need to redeploy the project the servlet code needs to be updated and recompiled if we have to change the look and feel of the application.

Que2: Define JSP Life Cycle?
The JSP page follows these phases.
  1. Translation of JSP page
  2. Page Compilation: Page is compiled into a class file.
  3. Page Loading: This class file is loaded
  4. Create an Instance: Instance of servlet is created.
  5. jspInit() Method is called only once when a jsp page is initialize.
  6. _jspService is called to handle service class.
  7. _jspDestroy is called to destroy it when the servlet is not required.

Que3: Which method we can override in JSP Life Cycle?
We can override jspInit() and jspDestroy method but we can not override jspService method. jspInit can be use for allocating resources like database connections, network connections etc. jspDestroy is use to free any allocated resources.

Other Related Post

Que4: What are Implicit objects in JSP? How many Implicit objects are there write there names?
Implicit objects in JSP are the Java objects that the JSP container makes available to developers in each page.
There are 9 implicit objects are there,
  1. Request
  2. Response 
  3. pageContext
  4. Session
  5. Application
  6. out
  7. config
  8. page
  9. exception

Que5: Difference between Include directive and Include Action in JSP?
  1. Include directive, includes the content of the specified file during the translation phase when the page is converted to a servlet. Include action, includes the response generated by executing the specified page (a JSP or a Servlet) during the request processing phase when the page is requested by a user.
  2. Include directive is used to statically insert the contents of a resource into the current JSP. Include action enables the current JSP page to include a static or a dynamic resource at runtime.

Que6: What is the different scope available in JSP?
There are 4 scope available in JSP
  1. Page: within the same page
  2. Request: After forward or include also you will get the request scope data.
  3. Session: After sendRedirect also you will get the session scope data. All data stored in session is available to end user till session closed or browser closed.
  4. Application: Data will be available throughout the application.

Que7: Difference between pageContext include and jsp:include?
Both are used to include resources at runtime however the pageContext.include() method always flushes the output of the current page before including the other components where as <jsp:include> flushes the output of the current page only if the value of flush is explicitly set to true.

Que8: Write the syntax of forward in JSP?
The <jsp:forward> action forwards a response from servlet or JSP page to another page
Syntax:
<jsp:forward page="/target_page"/>

target_page may be jsp, html or servlet

Que9: Write the syntax of include in JSP?
Syntax:
<jsp:include page="target_page" flush="true"/>

Que10: What are the standard actions available in JSP?
The standard actions available in JSP are,
<jsp:include>
<jsp:forward>
<jsp:usebean?
<jsp:setProperty>
<jsp:getProperty>
<jsp:param>
<jsp:plugin>

Que11: What are the different types of tags in JSP?
There are 4 types of tags in JSP
  1. Directive tag <%@ />
  2. Expression tag <%= %>
  3. Declaration tag <%! %>
  4. Scriptlet <% %>

Note: If you like this post then share it or have any question then just drop a comment. 


Post a Comment

13 Comments

  1. The JSP interview question shared is really interesting and informative moreover it give idea for us for answering the question my sincere thanks for sharing these information
    Java Training in Chennai

    ReplyDelete
  2. Very impressive and attractive one.. it is very useful for me to learn and understand, thanks for sharing your valuable information and time.. keep rocks and updating...


    Java Training in chennai | Java Training institutes in chennai

    ReplyDelete
  3. Good one, very informative.. thanks for sharing your views and ideas.. it is very useful to me..CCNA Training Institute in Chennai | CCNA Training Institute in Velachery.

    ReplyDelete
  4. Good Post..Really it was an awesome article...very interesting to read..You have provided an nice article....Thanks for sharing. MCSE Training in Chennai | Hardware and Networking Training in Chennai

    ReplyDelete
  5. This blog is really useful and it is very interesting thanks for sharing, it is really good and exclusive. Digital Marketing Summer Camp in Velachery | Digital Marketing Summer Classes in Chennai | Digital Marketing Summer courses in Taramani

    ReplyDelete
  6. Very Useful information that i have found. don't stop and Please keep updating us..... Thanks
    Summer Courses in Adyar | Summer Courses in OMR | Summer Courses in Velachery

    ReplyDelete
  7. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information... Great work
    Good Summer Courses for Photoshop in Guindy | No.1 Vacation Classes in Chennai

    ReplyDelete
  8. I really love reading and following your post as I find them extremely informative and interesting. This post is equally informative as well as interesting Summer Courses for Android in Perungudi | Summer Courses for IOS in Velachery | Summer Courses in OMR

    ReplyDelete
  9. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…

    Summer Camp for Kids in Chennai | Summer courses in Shozhinganallur | Summer classes in Chennai

    ReplyDelete

  10. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
    Summer Courses for Android in Perungudi | Summer Courses for IOS in Velachery | Summer Courses in OMR

    ReplyDelete
  11. Hi Thanks for the nice information its very useful to read your blog.
    Advanced SEO Training

    ReplyDelete