• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to implement MVC architecture with J2EE ?  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
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Servlets and JSPs provide the API to react on HTTP requests. You could of course write your own HTTP server and a custom API but what's the sense there? The wheel's not round enough for you...? In other words, servlets and JSPs (which are compiled into servlets) are the entrypoint between raw HTTP protocol and your application logic.

2) JSP "should" be used for generating the answer or output of the received HTTP request. Keeping that in mind, the Java code within a JSP should be directly related to generating HTML/WML/XML etc.
 
JeanLouis Marechaux
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using a MVC framework like Struts can help you to start
 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dharmin,
Which technology to use usually depends on the creation process and the number of people involved.
If you're doing a little site yourself and you're going to do all the visual and business logic yourself then you could easily use JSP's for the basic look of the site and call servlets for form processing, for example.
If you are part of a team in an ongoing project where static data is changins and the visual part of the site will be done by a specialist team of web desingers ( who don't know java ) then perhaps JSP's with beans and custom tags would help control the project better - and keep the web design people away from your code!
There are many other perfectly valid combinations which can be used but the main point I want to make is that it's the technology that should fit the project and not vice versa.
Hope this helps,
Terry
 
Christian Ebage
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dharmin,
you could use servlet to control access to other
resources like EJBs or to decide which objects
should process which request. The servlet could
use a JSP to display data obtained from a data source through an EJB. JSPs are mostly used to
generate dynamic web content, and Servlets are
used for business logic. You might still ask me
if servlets can be used for business logic, why
EJBs?
- you may use them when your application serves
multiple clients like web browsers, Swing

- your application needs to support concurrent
access, transaction management, needs to be
highly scalable, manage method level security
for several users of the system, persistence
management.
Ebage
SCJP
SCEA
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!