• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doPost() method signature

 
geeta vemula
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question from enthuware

Assuming that loginUser() and generateReport() are valid methods, which of the following statements about these servlets are true?



Select 1 correct option.
a
ReportServlet.java won't compile.

b
method generateReport() will never be executed.

c
method generateReport() will be executed only if a post request is sent to LoginServlet before ReportServlet.

d
share-session property should be defined to 'true' in web.xml for ReportServlet to get "userid".

e
None of the above.


Answer is c.

But can we write the doPost() like this without throwing ServletException and IOException? As they both are checked exceptions.

Thanks,
Geeta
 
Hasnain Javed Khan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Geeta,

Since you are over ridding the doPost method, the over ridding method can
1. Throw the same exception
2. Throw a subclass of the exception
3. Not throw any exception at all.

Hope that helps.

Kind Regards.
Hasnain Javed.
 
Devaka Cooray
Marshal
Pie
Posts: 4897
409
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For an example, if there is a code that handle the output stream or getWriter(), then the servlet would not compile without declaring IOException in the "throws" clause.

Devaka.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic