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.
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:
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 ]
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.
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.
Joined: Jun 08, 2007
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.