wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes best use of JSP/servlet combination Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "best use of JSP/servlet combination Question" Watch "best use of JSP/servlet combination Question" New topic
Author

best use of JSP/servlet combination Question

ruilin yang
Ranch Hand

Joined: Feb 25, 2001
Posts: 334
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

Joined: Feb 25, 2001
Posts: 334
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

Joined: Oct 09, 2001
Posts: 565
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


I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
ruilin yang
Ranch Hand

Joined: Feb 25, 2001
Posts: 334
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

Joined: Oct 09, 2001
Posts: 565
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

Joined: Aug 10, 2001
Posts: 3892
    
    5
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.


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 565
perhaps you can illustrate that with an example? (i was talking above about a shopping-basket page.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: best use of JSP/servlet combination Question
 
Similar Threads
can any one help me in finding wrong answers
jsp /servlets
sample questions
interesting j2ee questions, please help urgent !!
Check out the qtns for Part I