File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Servlet doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet doubt" Watch "Servlet doubt" New topic
Author

Servlet doubt

Brijesh shah
Ranch Hand

Joined: Mar 16, 2007
Posts: 90
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

Joined: Mar 26, 2002
Posts: 262
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.


Fun programming etcetera!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

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."


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Brijesh shah
Ranch Hand

Joined: Mar 16, 2007
Posts: 90
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

Joined: May 31, 2007
Posts: 3219
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"


Java Interview Questions and Answers Blog | Amazon.com profile | Java Interview Books
Minh Tran
Greenhorn

Joined: Jun 03, 2007
Posts: 19
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 ]

SCJP 1.4, SCWCD 1.4<br />email:mobject@gmail.com
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet doubt