• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Can We extend a java class or interface in a JSP page

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can We extend a java class or interface in a JSP page
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you can, as long as you put it in a declaration script.
I would not recommend it though.
 
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as I know:

(a) you cannot do that to a jsp page.
(b) your servlet can implement a custom interface
(c) your servlet cannot extend a custom java class (as it already extends HttpServlet class)
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lynette, why can't you ?
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry i misunderstood the question. yes you can do that.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use page directive to extend any java class.

<%@ page extends="your.java.class">
 
Sheriff
Posts: 67735
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pavan Igoor:
Use page directive to extend any java class.



Do so at your own risk. Even the JSP specification says to avoid doing this in favor of other means to achieve extending JSP functionality.
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pavn Igor wrote:Use page directive to extend any java class.

<%@ page extends="your.java.class">



From the above ...
JSP will automatically extend to HttpServlet class ..if we extend another class ,java does not support multiple inheritance ,how its achieved .
 
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

karimkhan pathan wrote:

Pavn Igor wrote:Use page directive to extend any java class.

<%@ page extends="your.java.class">



From the above ...
JSP will automatically extend to HttpServlet class ..if we extend another class ,java does not support multiple inheritance ,how its achieved .



Hi everybody, can anybody please explain why there is no error if I extend a java class in a jsp page, java does not support multiple inheritance and I am not getting any error.

Thank you all in advance
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you expect na error? The servlet produced from your JSP will extend only one class: either your custom class if you specify it in the page directive, or some container-provided class if you don't.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This whole topic makes me cringe, both if it's about the servlet class being generated from a JSP, or about Java classes defined inside of a JSP. Either is an indication of bad design choices.
 
Bear Bibeault
Sheriff
Posts: 67735
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ulf, is right on the money. The days of dealing with JSPs as if they were Java classes, or even putting Java code in a JSP are long long passed. Let's all catch up to 2010 and forget about this type of outdated nonsense.
 
Ranch Hand
Posts: 198
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Ulf, is right on the money. The days of dealing with JSPs as if they were Java classes, or even putting Java code in a JSP are long long passed. Let's all catch up to 2010 and forget about this type of outdated nonsense.



The code written inside the declaration tags been treated as members of the class..
So the classes defined in above JSP are treated as inner classes.

For extending a class in your Servlet... You have to implement Servlet and ServletConfig interfaces where you are not required to extend HTTPServlet, you can extend another class.

However can you give a requirement where you need to extend someother class in your servlet or jsp?
Is it not possible to do the things without extending a class?

Cheers!!!
Prabhakar
 
knowledge is the difference between drudgery and strategic action -- tiny ad
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic