★ wanayoo — archive 1999 http://javaboutique.webdeveloper.com/tutorials/Simple_JSP/index.htmlNouvelle recherche | Portail wanayoo


Find a Web Host With:
CGI Access
DB Support
NT Servers
UNIX Servers
Telnet Access

advanced search
Internet News
Internet Investing
IT
Windows Technology
Linux/Open Source
Developer
Interactive Marketing
xSP Resources
Small Business
Wireless Internet
Downloads
Internet Resources
Internet Lists
International
EarthWeb
Career Resources

Search internet.com
Advertise
Corporate Info
Newsletters
E-mail Offers
Be a Commerce Partner
Web Hosting
Breathing Problems?
Submit Your Site
Find a Consultant
Internet Jobs
Free Search Traffic
Find a Web HostFind a Web Host
Send a Press Release
Website Monitoring
Free Barter Account
FlashKit
Gif.com
HierMenusCentral
JavaBoutique
JavaScript.com
JavaScriptSource
WebDev Jobs
JustSMIL
ScriptSearch
StreamingMediaWorld
Web Hosts
WebDevelopersJournal WDVL
WebDeveloper.com
WebReference.com
XMLFiles.com
CGI
HTML
Java
JavaScript
Web Design and Promotion
Web Site Development
E-mail Address:


Can you receive
HTML e-mail?

Yes   No

Zip Code:



Tutorials :
Contents
Introduction
The "Customer Lookup" application
The "view"

A very simple JSP-architecture

by Keld H. Hansen

There's a lot of talk these days about J2EE and other advanced Java-architectures, and it's sure hot stuff--and interesting and relevant too. But you shouldn't forget that many smaller applications are best (and fastest) built using a simpler architecture.

This article will present a simple JSP-architecture and also a handful of useful techniques that will help you build web-applications fast, without losing focus on quality. If you are building prototypes, smaller applications, or simply want to experiment with Java-technologies, then this might be the architecture for you. The building blocks are JSP-pages and JavaBeans in an MVC-architecture. No servlets are used. This makes coding very fast, and has only one drawback as I see it: some errors in JSP-pages are very poorly diagnosed by today's application servers (servlet engines). When better JSP syntax checkers are built into the development tools this will probably become a minor issue.

The MVC architecture

The Model-View-Controller architecture is today a de-facto standard used in thousands of applications. The main idea behind this architecture is to separate business logic, presentation and program flow in a simple manner. In JSP-applications you may implement the MVC-architecture by:

The "C" (Controller): coding a controller that

  • handles common tasks like authentication
  • examines the requests from the user
  • invokes JavaBeans
  • controls error handling
  • controls module flow

The "M" (Model): coding a set of JavaBeans to handle the database access (or access to other external resources)

The "V" (View): coding a view for presentation of the data fetched by the beans

The controller is often programmed as a Java Servlet, but in this article we will use the simpler JSP-format, which is also commonly used for the view. Our application is therefore simplified by only containing JSP-pages and JavaBeans.

For each window--or page--in the application you'll need one controller and one view, and one or more JavaBeans. So we'll code a JSP-page for each controller and one for each view. But, don't be tempted to omit the controller for simpler web-pages, even if you could combine the controller and view into one file. Maintenance and further development on your application is greatly simplified if you always stick to the controller/view-pairs.

A command-driven controller

Another principle in our design is to let "commands" passed to the controller drive the application. A command will typically map to each "function" that is available on a web-page. Every controller will therefore start with identifying the request by looking at the command received. Since a request is most often initiated from a view-page shown in the user's browser, the command is typically sent to the controller by one of two techniques: either you send the command as part of the URL--e.g.

	
	ctrlcustomer.jsp?command=lookup

Or you submit the command in a field (often hidden) in an HTML-form.

More principles to follow

Before continuing with an example let's decide on a few other useful techniques to be used:

  1. A JSP error-page will be used to handle exceptions in a standardized way
  2. We'll use the Session object to store data that is not already stored in JavaBeans. A naming standard that we'll use for this data is <name-of-page>.<name-of-item> -- e.g. customer.address.
  3. We'll use a simple Java utility method called "cString" that will convert nulls to empty strings. Since form data--and often also data in the Session object--are stored as strings this makes it unnecessary to check for null-values.

Keld is a web architect working for one of the largest IT-companies in Denmark. He has more than 30 years of experience within the computer industry.

 
internet.com logo














WebDev News

Microsoft Buys Into SCO Group's Unix

Microsoft Joins Security Firms in Virus-Warning Pact

HP Releases Itanium-based Operating System





IronEye Cache
IronEye Cache from IronGrid, Inc. is a Java tool that easily enables intelligent caching in any JDBC application with no changes to source code.
Download of the Week
X Images
This is an Image Show applet. All images have a URL. If you double-click on an image you go to that url with specified frame.

JB User Poll
As a JavaBoutique Reader what kind of articles do you prefer?
The JavaBoutique Top 15:
1. ChompText
2. PingPong
3. DJPopMenu
4. NavBar
5. RushHour
6. 3DMaze
7. SonaliCalendar
8. Encyclo
9. AnimLetters_anim
10. AScroll2
11. Nibbly
12. Viewer
13. BMI
14. BMMenu
15. imageviewer
Want more? Check out our Top 100!

Refer-It
Affiliate Program and Referral Directory.
New on internet.com
Dell Well Positioned for the New Tech Environment
If technology is becoming a commodity, then Dell may be the best-positioned tech company of them all.

Keeping Tabs on Your Good Name
A new application, Google Alert, offers a new approach for staying up to date with your interests by routinely performing daily Google searches and sending e-mail notifications of new results that appear, complete with the links.

Security Product of the Year -- Norton AntiVirus Corporate Edition
Answer: Yaha, Klez, Lovegate, Bugbear and Backdoor. Question: What are five reasons Datamation readers selected Symantec AntiVirus Corporate Edition 7.6 as the Security Product of the Year?


Reports on security issues of ecommerce environments

Copyright 2003 Jupitermedia Corporation All Rights Reserved.
Legal Notices,  Licensing, Reprints, & Permissions,  Privacy Policy.
http://www.internet.com/