• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A JSP page's servlet class must extend

 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JSP page's servlet class must extend:

1. Is it an container generated class which implements Servlet interface.
or
2. an container generated class which implements HttpJspPage

Or something different.

Please confirm.

I think second one.

Regards,
Khushhal
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Khushhal,

I think the answer is both.
it has to implement both Servet, HttpJspPage(in case of HTTP)

for example
see this tomcat impl class: org.apache.jasper.runtime.HttpJspBase




What do you say ?
 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But Srinivasan

If we see in the hierarchy

HttpJspPage extends JspPage which in turn extends Servlet.

Then what's the need of implementing both.

Regards,
Khushhal
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes you are correct.

implementing HttpJspPage,( implictly implements Servlet)
Thanks for that.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


The JSP page need not extend any class. It must, however, implement the Servlet interface [as all jsp pages are ultimately converted into a servlet]
This is the hierarcy of the interfaces:
javax.servlet.Servlet <- javax.servlet.jsp.JspPage <- javax.servlet.jsp.HttpJspPage
Now, the base class of the JSP page, which is provided by the servlet container vendor, implements the javax.servlet.jsp.HttpJspPage interface. If you do not provide the 'extends' attribute of page directive, then this is the class that your jsp page's servlet extends from.


Thanks,
 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the base class of the JSP page, which is provided by the servlet container vendor, implements the javax.servlet.jsp.HttpJspPage interface


Means answer should be javax.servlet.jsp.HttpJspPage

Regards,
Khushhal
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Khushhal,


Means answer should be javax.servlet.jsp.HttpJspPage


I encountered some mock questions regarding this issues;
You don't know what exactly that class is. It is container dependent
but one thing is sure that the generated extends the class the must implement javax.servlet.jsp.HttpJspPage interface.

And yes, in the Enthuware, javax.servlet.jsp.HttpJspPage was not
correct answer. It was None of the above. Reasoning was the same as
I said above.



What do you say?

Thanks,
 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't say much..

but can only say, it should javax.servlet.jsp.HttpJspPage

As _jspService() method is also defined in javax.servlet.jsp.HttpJspPage

And from Enthuware Reasoning, it's reflected it should be javax.servlet.jsp.HttpJspPage only.

Now why they have written none of the above. That's the question to be answered.
Visit their forum and try to find out.

Regards,
Khushhal
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Khushhal,

If this is the situation, it would really really difficult to
chose from javax.servlet.jsp.HttpJspPage and None of the above.


Really hard!


Thanks,
 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't worry

Choose javax.servlet.jsp.HttpJspPage

Because other than these interfaces, I don't find any other interface in the API which a container generated class can implement.

So, question of None of the above doesn't even arise. I think so.

Regards,
Khushhal
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Original question from Enthuware:


Which of the following classes should a JSP page's servlet class must extend?

Select 1 correct option.
a javax.servlet.jsp.JspPage

b javax.servlet.jsp.HttpJspPage

c javax.servlet.jsp.JSP

d javax.servlet.jsp.Page

e None of these.



Answer : e

General comments:

The JSP page need not extend any class. It must, however, implement the Servlet interface [as all jsp pages are ultimately converted into a servlet]
This is the hierarcy of the interfaces:
javax.servlet.Servlet <- javax.servlet.jsp.JspPage <- javax.servlet.jsp.HttpJspPage
Now, the base class of the JSP page, which is provided by the servlet container vendor, implements the javax.servlet.jsp.HttpJspPage interface. If you do not provide the 'extends' attribute of page directive, then this is the class that your jsp page's servlet extends from.
 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chandra

Which of the following classes


First of all of them are not classes. You can easily make out that.

And Options c and d are straight away invalid.

And now we are left with options javax.servlet.jsp.JspPage, javax.servlet.jsp.HttpJspPage and javax.servlet(under None of these).

Among these, I would have gone for option b(javax.servlet.jsp.HttpJspPage).

As that sounds more appropriate because of the reasoning posted in earlier posts.

Regards,
Khushhal
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question gives us clue of "which class".

>>>Among these, I would have gone for option b(javax.servlet.jsp.HttpJspPage).

That is in case, the question were "which interface". Right?


Thanks,
 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,

That's right but in reasoning, they are all talking about which interface being implemented by the base class.

the base class of the JSP page, which is provided by the servlet container vendor, implements the javax.servlet.jsp.HttpJspPage interface.


And may be in the last line. They are describing the class.
you do not provide the 'extends' attribute of page directive, then this is the class that your jsp page's servlet extends from


So this one can be the right class.
And option e)None of these is in support of this class.

Regards,
Khushhal
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Khushhal,

I didn't understand this:

you do not provide the 'extends' attribute of page directive, then this is the class that your jsp page's servlet extends from

Please focus!
 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chandra

you do not provide the 'extends' attribute of page directive, then this is the class that your jsp page's servlet extends from


It means if you specify the extends attribute in the page directive, than that(value of extends attribute) will be the superclass of your jsp page's servlet.
Normally we never do it.As to inherit servlet properties in our jsp we have to make our jsp page's servlet to extend a base class implementing the javax.servlet.jsp.HttpJspPage interface.

That's is also by default i.e.
If we don't specify extends attribute, then the base class implementing the javax.servlet.jsp.HttpJspPage interface will be the superclass of your jsp page's servlet.


Regards,
Khushhal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic