Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Advantage of using JSP instead of Servlets  RSS feed

 
Malli Raman
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I know that JSP is for presentation purpose and servlets for business logic purpose. But my friend is questioning me why can't we use JSP instead of servlets as we don't require EJB's in this project. He is also saying that we can use JavaBeans for communicating with JDBC and also for the business logic.
Is his method is correct as per j2ee & MVC Standard.I am bit confused. Please help me.
Regards,
M.S.Raman.
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's nothing stopping you from purely using JSPs in your application, however using Servlets for business logic and dispatching tends to make the system more maintainable, and easy to understand. Also, if you have no need for EJB then accessing the database through a layer of JavaBeans is certainly a good idea - again for reasons of maintainability and that it decouples the presentation tier from the data tier.
Here's a chapter from Professional Java Servlets 2.3 that discusses some of the details around web application architecture in much more detail, including the issues around maintainability, reuse and so on.
Cheers
Simon
 
sameerleekha
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
What ur friend is saying is right.
U can put the business logic in the beans and call the beans in the JSP files in addition to calling the Jsp Files by another Jsp files for forwarding the request.
sameer
 
Jignesh Malavia
Author
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is one difference though! If you wish to distinguish between the different types of HTTP methods GET, POST, PUT, etc. for whatever reason, then you can easily override the corresponding doGet(), doPost(), etc. methods of the HttpServlet class if you go the servlets way.
In case of JSP pages, the generated class is not derived from HttpServlet and you will have to determine the HTTP methods yourself as
<%
String method = request.getMethod();
if ("GET".equals(method){
...
}
%>
-j
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!