This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confusion about servlet generated from JSP

 
Meghna Bhardwaj
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Tony Smith
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic