This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
Lynette, why can't you ?
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry i misunderstood the question. yes you can do that.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use page directive to extend any java class.

<%@ page extends="your.java.class">
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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: 43016
76
  • Mark post as helpful
  • send pies
  • 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
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic