Menu Close

jsp interview questions

What are Java Server Pages?

  • JSP is an internal servlet.
  • JSP is a server side technology.
  • JSP creates dynamic web pages in the form of HTML as response.

What are the Literals in JSP?

  • Null
  • Boolean
  • String
  • Integer
  • Float

What are the life cycle methods of JSP?

  1. public void jspInit()
  2. public void _jspService(ServletRequest request,ServletResponse) throws ServletException, IOException
  3. public void jspDestroy()

Write JSP implicit Objects and their types?

  1. out -> JspWriter
  2. request -> HttpServletRequest
  3. response -> HttpServletResponse
  4. config -> ServletConfig
  5. session -> HttpSession
  6. application -> ServletContext
  7. pageContext -> PageContext
  8. page -> Object
  9. exception -> Throwable

Differentiate Include Directive and Include Action?

  • Include Directive:
    • Includes content at page translation time
    • Preferred in Static Pages
    • Includes Original content of the page
    • Cannot invoke include() method
    • Page size can be increased in the run-time
  • Include Action:
    • Includes content at page request time
    • Preferred in Dynamic Pages
    • Does not include Original content of the page
    • Can invoke include() method
    • Page size is fixed

Explain JSP Action Tags?

  • jsp:forward = Forward the request and response to another resource
  • jsp:include = To include another Resource
  • jsp:useBean = Locate/Create another bean object
  • jsp:setProperty = Sets the property value in a bean object
  • jsp:getPropety = Prints Property Value of the bean object
  • jsp:fallback = Used to print a message if the plug in is working
  • jsp:plugin = Used to embed another component such as an applet
  • jsp:param = Sets the Parameter value

How to include static files in a JSP?

  • Using include directive, we can include static page.
  • This way the inclusion is performed in the translation phase once.
  • The relative URL must be supplied for file attribute.

How can we avoid errors on display in a JSP Page?

  • We need to setup an error JSP page.
  • In the error JSP page set isErrorpage=”TRUE”.

Explain JSP Declaration?

  • The declaration tag can be used to declare fields and methods in JSP code.
  • The code written inside the JSP declaration is enclosed in <%!  %> tag.
  • It is placed outside the service() method of the auto-generated servlet.

Differentiate “include directive” and “jsp:include action”?

  • include directive the content to other resource is added to the generated servlet code at the time of translation
  • include action happens at runtime.
  • We can pass params to be used in the included resource with jsp:param action element
  • In JSP include directive we can’t pass any params.

What is JSP Expression Language?

  • We can use scriptlets and JSP expressions to retrieve attributes and parameters in JSP with java code and use it for view purpose.
  • JSP Specs 2.0 introduced Expression Language (EL) through which we can get attributes and parameters easily using HTML like tags.
  • Expression language syntax is ${name}.
  • Expression language use implicit objects and EL operators to retrieve the attributes from different scopes and use them in JSP page.

What are the JSP custom tag components?

  • JSP Custom Tag Handler
  • Creating Tag Library Descriptor (TLD) File
  • Deployment Descriptor Configuration for TLD

How JSP standard tags configure in web.xml?

  • JSP standard tags do not configure in web.xml.
  • Configure TLD files are inside the META-INF directory of the JSTL jar files.
  • At the time of web application loading, container finds TLD files inside the META-INF directory and automatically configures them to be used directly in the application JSP pages.

What is use of scriptlet tag?

  • A scriptlet is used to including java code in a JSP page.
  • Syntax is <% Java Code %>

What are the different types of JSP tags?

  • JSP standard tags
    • Scriptlet tags
    • Action tags
    • Directive tags
  • Custom tags
  • Presentation tags

What are the standard actions in JSP?

  • <jsp: include>: Used to specify a response from the servlet or a JSP page into the current page.
  • <jsp: forward>: Used to send a reply from the servlet/JSP page to another page.
  • <jsp: useBean>: Allows a Java Bean to get accessible from a page and initializes the bean.
  • <jsp: setProperty>: Used to set the Java Bean properties.
  • <jsp: getProperty>: Fetches the property value from a Java Bean component and appends it to the response.
  • <jsp: param>: Used with actions like <jsp:forward> and <jsp:, or plugin> to append a parameter to the request.
  • <jsp: plugin>: Specifies whether to add a Java applet or a JavaBean to the current JSP page.

Define Expression tag in JSP?

  • Expression tag is used to embed Java values directly in the output.
  • It contains a scripting language expression that is classified, then converted to a string and then inserted where the phrase comes in JSP file.
  • Its syntax is <%=expression%>.