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

Why servlet in WebApplication

 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frieds, I am new to servlet why to use servlet in webapplication. what i know is " use servlet as a controller in mvc and to implemnent business logic . is it correct ? One more thing reason for implementing business logic with servlets , why not jsp.
 
Teena George
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Servlets came into picture as a real good alternative to CGI. Compared to CGI, servlets have a lot of advantages. Have a look at it
This is also good

Servlets can be used as a presentation layer technology. Here we will write HTML tags in java.
Ofcourse, for the ease of use and code maintainability, and a lot more advantages, we can use jsp or any of the similar kind of presentation layer technologies.

(Do a google search for servlets vs jsp.)

Regards,
Teena
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Friend, I asked why servlet for implementing business logic. why not jsp.
 
Teena George
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

As far as I know, we should not implement business logic in our presentation logic (servlets, jsp, xhtml etc). It should be handled in our business logic layer. For e.g. using EJB.

Regards,

Teena
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suppose am not using ejb. i searched in google "Based on the situation we can decide.For example we are using Database related things(Opening a connection,executing statements etc.i.e, called as business logic)it is better to use Servelts(Re usability is possible with servlets but not with jsp's)Most of cases we use jsp's for presentation.i.e,the output nthat has to sent to browser can be done by making use of jsp's " is it correct?
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rajendra,

Most of the things a servlet can do a JSP also can do (a JSP eventually is translated in to a servlet). But the JSP is meant to provide the facility for creating the "view" part of the application. It's easy to write HTML in JSP rather than in servlet.
 
Teena George
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


"Based on the situation we can decide.For example we are using Database related things(Opening a connection,executing statements etc.i.e, called as business logic)it is better to use Servelts(Re usability is possible with servlets but not with jsp's)

Can you provide the link where you have seen this?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65339
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use a hammer to bang in a screw, and you can drive on the wrong side of the road if you like. Neither is smart.

Using the right tool for the job, and following accepted conventions and best practices is smart.

Servlets and JSP are intended, and best suited, to be used as part of the Presentation Layer of web applications. As such neither should be used for business logic, which should be ensconced in its own UI-agnostic layer.

Perhaps this article can help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic