13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

416Chapter 18Servlets: Java Pressed into Service18.7DESIGNING A BUDGETPRO SERVLETWhen designing a servlet, there are many different patterns to follow. We can’thope to cover all the approaches that can be used for effective servlet programming.What we hope to do is show you our previous BudgetPro GUI applicati<strong>on</strong>rewritten as a servlet, so that you can see the mechanics of a working servletapplicati<strong>on</strong>. From this, you can become accustomed to the mechanics of aservlet so that you’ll feel comfortable with other approaches, too. All servletsneed to use these basic mechanisms.Our BudgetPro GUI applicati<strong>on</strong> was started from the command line, witha name for the budget and a total dollar amount. We’ll use a static HTML pagewith a form for supplying that informati<strong>on</strong>. That will invoke our servlet. Theservlet will use HTML pages analogous to the windows we used in ourGUI—there will be a main screen that shows the current account listing itssubaccounts, and there will also be a screen for creating new subaccounts.One nice feature of HTML-based Web applicati<strong>on</strong>s is that you can usehyperlinks as a way to both select something and take an acti<strong>on</strong> <strong>on</strong> it. We’ll usethat feature in lieu of a View Subaccount butt<strong>on</strong>. Instead of selecting a subaccountand then pressing View Subaccount, the user will <strong>on</strong>ly have to click <strong>on</strong>the name of the subaccount. As a hyperlink, it will make the request to theservlet to view that subaccount.We will still use a butt<strong>on</strong> to send us to the screen for creating the subaccounts.We could have used a hyperlink, but this makes the browser page looka bit more like the GUI versi<strong>on</strong>.18.7.1 PrototypeWhen designing servlets, it’s handy to use static HTML pages as a prototypefor the work to be d<strong>on</strong>e. You can mock up the various screens using HTML,simulate interacti<strong>on</strong>s by using hyperlinks to move between the screens, and geta feel for what the screens and interacti<strong>on</strong>s will look like.Such a prototype also serves as a “runnable” specificati<strong>on</strong>. It can sometimesbe easier to show the acti<strong>on</strong> than to describe it with words. And if you take carewhen you are building these static HTML pages, most of the HTML can bereused directly in the final product. (This will be even more true when we getto JSP.)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!