This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing an interface in JSP- Possible?

 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am aware of the extends attribute in the page directive.Am wondering, if a implements attribute also exists?
Thanks in advance.
Regards

------------------
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
 
Phil Hanna
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, there is no mechanism for doing this, other than writing your own superclass that implements the interface, and then having your JSP specify that superclass with <%@ page extends="mysuperclass" %>
You can, however, define an inner class that implements the interface, and contain an instance of the inner class:

------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
Website: http://www.philhanna.com
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Phil,
Thanks for the response.
I also thought that implements attribute is not possible in JSP.However Java Servlet Programming,Jason Hunter with William Crawford disagrees with us at Page 40-41, where he introduces a directive tag called implements
Am quoting the information in this post :

Specifies the list of interfaces the servlet should implement.Multiple interfaces can be given by comma-seperated list or given through multiple import directives.For example:

The default behaviour is not to implement anything

I am trying this directive now, and would keep you informed.
Thanks once again.
Regards,

------------------
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Desai Sandeep:
I also thought that implements attribute is not possible in JSP.However Java Servlet Programming,Jason Hunter with William Crawford disagrees with us at Page 40-41, where he introduces a directive tag called implements

It may be/have been there in some versions or implementations of JSP, but it's certainly not part of JSP 1.1. Read 2.7.1.1 in the spec.
- Peter
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter,
Found out that it was a part of JSP 0.91.But why have they removed the implements directive then?
Thanks in advance,

------------------
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
 
Dustin Marx
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cannot think of a good reason for having "implements" functionality in a JSP. Do you have a particular usage in mind?
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, yes, otherwise the only workaround is what Phil has suggested

[...] other than writing your own superclass that implements the interface, and then having your JSP specify that superclass with <%@ page extends="mysuperclass" %>

Why should JSP (which is based on Java!!) require this workaround.Wouldn't implements directive be better!!
I still cannot understand why they removed this directive.Obviously,there must be a good reason to do so..we need to find out!!
Regards,
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56

  5. [This message has been edited by Desai Sandeep (edited April 26, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic