Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet doubt

 
Brijesh shah
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All;

Can anybody tell me by using which method we can apply business logic in servlets...and syntax of that method...I asked this question in my interview so i was thinking about service()...but i think its wrong..

Anxiously, looking forward for your reply.

Thanking you in advance.

Thanks & Best Regards,
Brijesh Shah
 
Dave Wingate
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, without being able to clarify the question, I might guess that your interviewer was expecting you to name the doPost(HttpServletRequest req, HttpServletResponse resp) method in HttpServletRequest
HTTP post requests typically correspond to a request to process some data submitted by the user, perhaps some 'business' data.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the interviewer is knoweledgable, the correct answer was "You don't do business logic in a servlet. You delegate it to a lower tier."
 
Brijesh shah
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was subjective test in an interview in which they have specifically mentioned "By using which method you can apply business logic in the servlet and name that method"
 
arulk pillai
Author
Ranch Hand
Posts: 3385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An abiguous question. I would say that doGet() or doPost() method would delegate the business logic to the service tier (aka business logic layer).

May be the interviewer is trying to expect your answer of "No business logic in the servlet"
 
Minh Tran
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if the application has no choice to implement business logic in different tier and it must be in the Servlet...According to my opinion, I think you were right, it might be in the service() method.

I always ask back interviewer if I can not answer his question. For that, I can learn new things(if any) or discuss if the question is not clear enough to answer ... or you did answer so well and the interviewer want you to get stuck (your car is running faster than his car)
[ June 13, 2007: Message edited by: Minh Tran ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Minh Tran:
if the application has no choice to implement business logic in different tier and it must be in the Servlet...According to my opinion, I think you were right, it might be in the service() method.


With the exception of a few rare cases, you should never override the service method. This method analyzes the request and delegates to either the doPost, doGet, or one of the other do... methods.

If Bear's answer did not satisfy the interviewer and you were pushed to name a specific method, arulk pillai's answer would have been perfect.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic