wood burning stoves 2.0*
The moose likes JSP and the fly likes Confusion about servlet generated from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Confusion about servlet generated from JSP" Watch "Confusion about servlet generated from JSP" New topic
Author

Confusion about servlet generated from JSP

Meghna Bhardwaj
Ranch Hand

Joined: Jun 08, 2007
Posts: 109
HI All,

I have a question about servlets generated from JSP. After writing a simple JSP page I can see the output on my webpage. I then went to look at the generated servlet which exists as a XXX.java file, when I look inside it I was expecting to find a doGet() and doPost() method among others, however there is no such method. It has jspInit(), jspDestroy() and jspService() methods.

So is this the servlet file or JSP, or are they one and the same? If so why are the other servlet methods not present like doGet and doPost?
I am using Eclipse IDE and Websphere CE.

Would really appreciate all comments.

Many thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Take a look at what class is being extended. You will see that HttpServlet is not being directly extended. It will be dependent upon container, but for Tomcat you will see that the class extends:

org.apache.jasper.runtime.HttpJspBase

At some point, this class' hierarchy will extend the servlet base class and provide all the low-level handling. The nice part of this is that, as JSP authors, we don't care!

P.S. I highly doubt that doGet and doPost are implemented anywhere in the processing of a JSP. It's much more likely that the service() method is being directly overriden. But again, we don't know, and we don't need to know.
[ October 04, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tony Smith
Ranch Hand

Joined: Jul 07, 2007
Posts: 229
Hi, the file you opened should be correct and that is how normally generated servlet class look like. jspService() will take care of all the doget and dopost requests.

I believe in the original regular servlet, there is a service method that gets called, it will then call doget and dopost method. As in the generated servlet, I am not sure if there is a hidden doget and dopost hiding somewhere in other files. Also I think you don't need to worry about it. People who programmed the container will take care of it.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Originally posted by Tony Smith:
jspService() will take care of all the doget and dopost requests
Not exactly. The JSP service method will get called as a result of a request, but we have no idea how. As I said, there may not even be any doPost or doGet implementations -- but the beauty is, we don't have to know.
Meghna Bhardwaj
Ranch Hand

Joined: Jun 08, 2007
Posts: 109
HI,

Thanks for the responses, you are right the class extends org.apache.jasper.runtime.HttpJspBase

I was just curious and wanted to understand what was going on,
but you all are right somewhere in the super class the doGet()
and doPost() do appear however, they are not in the servlet class I extended.

I was just following a book which seems to refer to these methods, so I wanted to ahve a look at them.

Ok thank you folks!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Confusion about servlet generated from JSP
 
Similar Threads
POST or GET
Service method
Servlet issue
Are JSPs Servlets?
doView and doConfigure doEdit and doHelp