Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doGet() method in Servlets

 
Fayyazuddin Syed
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Sincerely;
Fayyaz
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3817
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

HTH,
Paul.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic