How do I get a JSP page to implement a Java interface?

Frank Steidinger

A JSP page can't directly implement an interface. If you really need to do this you'll have to define a superclass for your page which implements the interface. If you declare this superclass to be abstract you can defer the implementation of the interface to the JSP page. This superclass will have to implement the interfaces HttpJspPage and Servlet too, otherwise you will get a compilation error from the JSP compiler.

If the interface you want to implement were named MyInterface, you could define a class Intermediate:


public abstract class Intermediate implements MyInterface, HttpJspPage, Servlet {<BR>
  protected ServletConfig  config;
  public String  getServletInfo() { return "JSP Page"; }
  public ServletConfig  getServletConfig () { 
    return  this.config; }
  public void  init(ServletConfig config) throws ServletException
  {
    this.config = config;
    jspInit();
  }
  public void destroy () { jspDestroy(); }
  public void  service(ServletRequest request, ServletResponse response) throws ServletException, java.io.IOException
  {
    _jspService ((HttpServletRequest) request, (HttpServletResponse) response);
  }

}

Then you can subclass this Intermediate in your JSP page using the page directive:

<%@ page language="java" extends="Intermediate"%>
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact