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

Servlet vs JSP vs JSF

 
Raghavendra Desoju
Ranch Hand
Posts: 95
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to decide on best suited UI approach Servlets/JSP/JSF based on the use case?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's never servlets versus JSP. It's servlets and JSP.

So your choice comes down to: servlets and JSP, or JSF.
 
Raghavendra Desoju
Ranch Hand
Posts: 95
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I am really weak on UI front. I would like to get enough knowledge before I appear for Part 1 of the exam.

What are the key points we need to consider to choose between these two? Is there any good material that can help in this regard?

Thanks, Raghu
 
K. Tsang
Bartender
Posts: 3583
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a MVC web app, servlet and JSP is like the controller and view. Whereas JSF the stuff you write is model (managed beans) and view, the controller is the FacesServlet provided.

JSF is a "component"-based framework.

When to use which depends on the complexity of the UI design. For example, if there is a table that requires column sorting, pagination, or dynamic row editing then JSF is better. JSP will take much more effort in implementing those features.
 
Stefan Evans
Bartender
Posts: 1807
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am far from a JSF expert, but here is my 2 cents.
It comes down to the complexity of your model and the UI requirements - cost vs benefits.
JSP is easier than JSF, but won't do as much.


Guidelines I would consider:
No/Minimal UI  - servlets. 
Simple UI - JSP
Complicated/Component based UI - JSF


SimpleUI - JSP with a tag library like JSTL (no scriptlets)
Relatively simple HTML pages
- one "domain" of model information being shown
- simple conditional / looping logic that can easily be expressed in HTML


Complicate UI - JSF
- multiple "sections" of a screen.  i.e. dashboard type interface
- more complicated object model
- more complicated input paradigms - formatters.

 
Raghavendra Desoju
Ranch Hand
Posts: 95
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for sharing your thoughts.
 
Tim Holloway
Saloon Keeper
Posts: 18365
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing to note about JSF - it puts a lot of emphasis on data input from forms. One of the greatest conveniences of JSF is that it validates every data item on the form and will refuse to process until each and every input control contains a valid value. If one or more control values is invalid, the form is re-displayed with the user input (no need for the user to re-enter the data) and it's an easy thing to design forms where the error messages for a control are displayed next to the control itself. Which is very much preferable to the lazy forms I routinely see that basically say "One or more values on this page are in error. Please correct them and resubmit". About the only thing that approaches that level of annoyance to me are fields for long numbers that cannot allow dashes or spaces in them .

But there's one very important thing to note. Ultimately, it's not about JSP/servlet versus JSF, it's about whether to use JSF or not. JSF does not forbid the presence of non-JSF servlets or JSPs in the same webapp. In fact, one of the most common admonitions I make in the JSF forum is against trying to force JSF to output XML or non-HTML documents such as Excel spreadsheets, Word Documents or PDFs. JSF is not intended for those purposes, so while it can be done, it's simpler to do those parts of the webapp without JSF.

JSF is not a jealous all-or-nothing architecture. JSF code can live in perfect harmony not only with JSP/servlet code, but Spring Web, Struts, Apache CXF web services, and more all in the same webapp.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic