Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

best use of JSP/servlet combination Question

 
ruilin yang
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most web applications require logic for validating form input and determining the
next page to display. Given long term maintenance and reuse objectives,
what is the BEST design to implement this logic?
a) A JSP that both validates form input and determines the next page.
b) Validate form input in a JSP and determine the next page in a servlet.
c) Validate form input in a servlet and determine the next page in a JSP.
d) A servlet both validates form input and determines the next page.
Single Select - Please select the best answer (one and only one choice must be selected).
Please comment for the best answer
Thanks,
Ruilin
 
ruilin yang
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we let Servlet to do validation and control for the next page we can have as little as java code in JSP (or become pure html). This has advantage to separate presentation from logic. However, in this way we do not use the advantage of JSP.
So what is the best ?
Ruilin
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely if you are using JSP, you have defined the pages that the user calls and you don't have to have a servlet that works out which one to go to?
I have a JSP called shopping_basket.jsp that does everything required for a shopping basket - it saves a new item when you go to it with a article_id, it allows you to check-out and then says "thanks" and generates a confirmation e-mail, it allows you to change the quantities of items and it calculates the price etc.
If the user wants to go somewhere else, s/he clicks a link.
Adam
 
ruilin yang
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam,
Yes JSP can do display and also if not all the most functionality of a servlet.
How ever, my question is:
Given long term maintenance and reuse objectives,
what is the BEST design to implement this logic (refer to the original question above)?
Please comment
Thanks,
Ruilin
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what i mean is this: there is no "next page" requirement. why do you need a next page? sort it out in the one page.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam,
Only the most simplistic applications have a purely linear flow with no "next page" requirement. Most sites have branching flows where a user response might result in one of N pages being displayed. Putting that sort of logic in the JSP results in nasty looking JSP's where there is a lot of if statements in the Java code prior to any HTML being output (and the HTML may not even be output if it has to redirect to another page!)
For reuse, it's best to keep the Java segregated from the HTML. Thus the MVC paradigm.
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
perhaps you can illustrate that with an example? (i was talking above about a shopping-basket page.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic