This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes doGet() method in Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "doGet() method in Servlets" Watch "doGet() method in Servlets" New topic

doGet() method in Servlets

Fayyazuddin Syed

Joined: May 14, 2006
Posts: 10
Dear fellow developers:

In the HFSJ book, the doGet() method is sometimes listed as throwing only IOException, and in other cases, it is shown to be throwing both ServletException, IOException. Is this an error in the book, or is there a reason why in some cases the doGet() method would only throw IOException vs throwing both ServletException, IOException?

Just wondering.

Thanks in advance.
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3253
The throws clause of doGet() of HttpServlet class has ServletException as well as IOException. So the subclass servlet's doGet method can have a throws clause containing either of these exceptions (or both or none, refer SCJP ).

Now, based on what the servlet is doing in its doGet method, it can define its throws clause. For example, if the method body does not call any method that throws IOException, the method declaration of doGet may choose not to list IOException in its throws clause. Same for ServletException.

So it may not really be an error.


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Consider Paul's rocket mass heater.
subject: doGet() method in Servlets
Similar Threads
exception Tag in web.xml
Question about BufferedReader on Servlets
About doGet and doPost of Services
Compilation Error
please reply urgently!!!