Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

When to use Jsp when to use servlets and when to use Bean / EJB ?  RSS feed

 
Dharmin Desai
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Friends,
Anybody can answer following questions ?
1. Why to use JSP or Java Bean or EJB, when everything can be done with Servlets ?
=> Bean and EJB is reusable component so one can understand the use for Bean and EJB, But why servlet or Jsp ?
2. Moreover, Which things (java code), i need to put at Jsp and which code i need to put at Servlet and again which code should be at Bean/EJB ?
3. Anybody can help to implement MVC Architecture with J2EE technology ?
Thanks and regards
Dharmin
 
Srinivas Saranu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
you can do everything using JSP what ever u can do with servlets.but coming to servlets, u have to combine both HTML and java code which is tedious when the HTMl code is huge.In this situation using JSP is very comfortable, as jsp seperates presentation logic and business logic.
The same java code will work both in servlets and JSP's.It's always good to use the combination of servlets and JSP.
coming to MVC architecture--> use EJB's as model and JSP as View(presentation part)and servlets as controller
 
Randall Twede
Ranch Hand
Posts: 4583
6
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wouldnt it be a lot of work writing a servlet to display a page when the only java code needed is this: request.getParameter("name")?
jsp also has the advantage that you dont have to recompile and then restart the server to make changes.
 
Jagdeep Singh
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP decouples presentation from logic. So any page change is simpler. servlets should be used for business logics or can be Front controller or can be just a controller. JavaBeans can be reusable data components. EJB can be used to implement Value Object pattern.
Just read J2EE design patterns that will help you understand the role of each of these.
 
Dharmin Desai
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks friends,
Actually, i need to do some more homework !
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But please remember that JSP is not the only page-building technology.
A templating approach (such as WebMacro or Velocity) offers the same benefits of separating presentation from logic, without the hideous JSP syntax and the irritating compilation step on the deployment box. And the powerful expression language built into either WebMacro or Velocity is miles ahead of the first clumsy steps in the JSP Standard Tag Library.
Similarly, EJB is not the only option for persistence of data.
Fundamentally EJB is just an object-relational mapping system, and there are several of those to choose from. Decoupling details of the storage mechanism from the object model is usually a good choice, but you don't always need EJB to achieve it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!