2

We can define multiple attributes in a single page directive or we can have multiple page directives in a single JSP page. But can we extend multiple classes in any jsp page using extends attribute?

for eg:

<%@ page extends="Class1" %>
<%@ page extends="Class2" %>
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
User_86
  • 265
  • 1
  • 4
  • 13
  • Why are you using something like this? It would be better to not use scriptlets or any other business logic handler in JSP directly. – Luiggi Mendoza Jun 17 '14 at 17:45
  • @LuiggiMendoza: I'm not following this kind of code. I just wanted to know can we do it or not? – User_86 Jun 17 '14 at 17:48

1 Answers1

3

extends Specifies a superclass that the generated servlet must extend

This means that writing <%@ page extends="Class1" %> is kind of equivalent to

class MyClass extends Class1 {}

because JSP page is compiled to java class with similar name (depending on container). Since java does not support multiple inheritance writing more than one JSP attribute extends must be illegal.

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • Thanks for your question that caused me to read about this JSP attribute that I have never used and even did not know that it exists. – AlexR Jun 17 '14 at 17:54