Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

doPost() method signature

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 6914
1314
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
It wasn't my idea to go to some crazy nightclub in the middle of nowhere. I just wanted to stay home and cuddle with this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic