JSP FAQ  «Prev  Next»

JSP Interview Questions – FAQ

  1. What is JSP technology?

    JSP (Jakarta Server Pages, formerly JavaServer Pages) is a server-side technology built on top of Servlets. It allows developers to embed Java code within HTML to create dynamic web content. JSP simplifies web application development by separating presentation (HTML, CSS) from business logic (Java).

  2. How did JSP evolve with version 2.0 and later?

    JSP 2.0 introduced significant improvements, including:
    • A unified Expression Language (EL) for accessing data more easily.
    • Tag files and functions for simpler custom tag creation.
    • Better integration with JavaServer Faces (JSF).
    Today, JSP is considered a legacy technology, with JSF and modern Jakarta EE APIs (such as Jakarta RESTful Web Services) often preferred for new projects.

  3. What are JSP implicit objects?

    Implicit objects are pre-created by the JSP container and available in every JSP page without explicit declaration. They provide access to request, response, and application data:
    • request
    • response
    • pageContext
    • session
    • application
    • out
    • config
    • page
    • exception


  4. What are JSP scripting elements?

    There are three classic scripting elements:
    • Declarations: <%! ... %> – define fields and methods.
    • Scriptlets: <% ... %> – embed Java code in the JSP page.
    • Expressions: <%= ... %> – output the result of a Java expression.
    Best practice: Avoid scriptlets and use EL + JSTL instead for cleaner, maintainable pages.


  5. Why were JSP pages widely used for dynamic web applications?

    JSP pages allowed developers to mix Java code with HTML without requiring browser plug-ins. They also supported separation of concerns: web designers could focus on layout, while developers wrote the business logic. However, modern Jakarta EE applications typically use frameworks like JSF or external front-end frameworks (React, Angular) with REST APIs instead of raw JSP.

  6. Is JSP technology extensible?

    Yes. JSP supports extensibility through:
    • Custom tags defined in tag libraries.
    • JSTL (Jakarta Standard Tag Library), which provides reusable tags for iteration, conditionals, internationalization, and database access.


  7. What are the two types of comments in JSP?

    <%-- JSP Comment --%>   (Not sent to the client)
    <!-- HTML Comment -->   (Visible in the page source sent to the client)
    

  8. Why was SingleThreadModel deprecated?

    The SingleThreadModel interface (Servlet 2.4) was deprecated because it did not effectively solve concurrency issues and created performance problems. Modern best practice: Always handle concurrency by synchronizing access to shared resources or using thread-safe components.

  9. What is the difference between custom JSP tags and JavaBeans?

    • Custom JSP tags: Define new XML-like tags, grouped in tag libraries, to encapsulate complex behavior and simplify JSP pages. Require:
      1. A tag handler class
      2. A tag library descriptor (TLD)
      3. JSP pages that use the tag
    • JavaBeans: Reusable components that encapsulate state and logic. They typically provide properties with getter/setter methods and can be accessed via EL in JSP pages.

SEMrush Software