| ★ wanayoo — archive 1999 http://javaboutique.webdeveloper.com/tutorials/Simple_JSP/index.html | Nouvelle recherche | Portail wanayoo |
![]() | ||||||||||||||||
Tutorials :
A very simple JSP-architecture
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 architectureThe 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
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 controllerAnother 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 followBefore continuing with an example let's decide on a few other useful techniques to be used:
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.
|
| |||||||||||||||
