24. How can JSP inheritance be achieved

The JSP super class and sub-class need to satisfy certain requirements as defined in the sections below. First let us assume we are using the HTTP protocol. Then mapping of other protocols is an easy task.

Requirements for the Super Class

  • It must implement the HttpJspPage interface.
  • It will obviously extend the HttpServlet class. It needs to implement the three main lifecycle methods of the servlet:
    • init
    • destroy
    • service

These implementations are ‘final’. In addition, the method getServletConfig must be implemented to return the ServletConfig object, passed onto the servlet during initialization.

This super class now necessitates the base class to actually implement the JSP version of these three function calls: jspInit, jspDestroy, and _jspService, by providing abstract declarations for the same

    • public abstract void jspInit()
    • public abstract void jspDestroy()
    • The signature for the _jspService method depends on the kind of JSP Engine that has been deployed. For eg: if Weblogic is the JSP Engine, the signature is:
public abstract void _jspService(HttpServletRequest request, HttpServletResponse response);

The init method is called jspInit, the destroy method – jspDestroy, and the service method as _jspService.

Requirements for the sub class

The sub class may or may not provide the jspInit and jspDestroy method, based on whether the parent class provides it.

Code snippet for the JSP sub class

<%@ page extends=”JSPPageSuper”%>

<%

//Any server processing

%>

<HTML>

</HTML>

Note the first line where the page extends the JSPPageSuper servlet.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: