HOME  |    TRAINING  |   FREE TUTORIALS   |   JOBS
Find out more about our new RSS feed.
FREE Tutorial
PROFESSIONAL JSP : ARCHITECTURE PART 4 - THE "PAGE-CENTRIC" APPROACH

CATEGORY
SEARCH OUR OTHER TUTORIALS

DESCRIPTION

We start by looking at architectures based on the page-centric or client-server approach. We will look at the page-view and page-view with bean architectures.
Click here to be kept informed of our new Tutorials.


This free tutorial is a sample from the book Professional JSP.


Applications built using a client-server approach have been around for some time; they consist of one or more application programs running on client machines, and connecting to a server-based application to work. (A good example would be a PowerBuilder or Oracle Forms based system.) CGIs and pre-Servlet applications were generally based on this simple 2-tier model, and with the introduction of Servlets, 2-tier applications could also be created in Java.

This model allows JSPs or Servlets direct access to some resource like a database or legacy application to service a client's request: the early JSP specifications termed this a "Model 1" programming approach. The JSP page is where the incoming request is intercepted processed, and the response sent back to the client; JSPs only differed from Servlets in this scenario by providing cleaner code, and separating code from the content by placing data access in beans.

This is illustrated in the figure below.

The advantage of such an approach is that it is simple to program, and allows the page author to generate dynamic content easily, based upon the request and the state of the resources.

However this architecture does not scale up well for a large number of simultaneous clients since there would be a significant amount of request processing to be performed, and each request must establish or share a potentially scarce/expensive connection to the resource in question. (A good example would be JDBC connections in servlets or JSPs and the need for connection pools.)

Indiscriminate usage of this architecture usually leads to a significant amount of Java code embedded within the JSP page. This may not seem to be much of a problem for Java developers but it is certainly an issue if the JSP pages are maintained by designers: the code tends to get in the designer's way, and you run the risk of your code becoming corrupted when others are tweaking the look and feel.

Of course, it is not necessary to use JSPs, to separate code and presentation in servlets: the use of templates is popular. There are a lot of toolkits that facilitate this, such as ATP (http://www.winwinsoft.com/atp/), MindTemplate (http://www.mindbright.se/english/technology/products/mindtemplate), or the more popular WebMacro (http://www.webmacro.org/), FreeMarker (http://freemarker.sourceforge.net), and PreparedHtml (http://www.its.washington.edu/~garth/prep.html)

Page-View

This basic architecture involves direct request invocations to a server page with embedded Java code, and markup tags which dynamically generate output for substitution within the HTML.

This approach has many benefits. It is very easy to get started and is a low-overhead approach from a development standpoint. All of the Java code may be embedded within the HTML, so changes are confined to a limited area, reducing complexity. The figure below shows the architecture visually.

The big trade-off here is in the level of sophistication. As the scale of the system grows, some limitations of this approach surface, such as including too much business logic in the page instead of factoring forward to a mediating Servlet, or factoring back to a worker bean. As we discussed earlier, utilizing a Servlet and helper beans allow us to separate developer roles more cleanly, and improves the potential for code reuse. Let's start with a fairly simple example JSP page that follows this model, handling requests directly and including all the Java code within the JSP source page.

We begin with a basic description of the example application. All the examples in this chapter use the JSWDK version 1.0.1, using the default web application directory structure for simplicity. Thus, the JSP and HTML source are under the <jswdk-root>/examples/jsp/ subdirectory and the Servlet (see later) is under <jswdk-root>/examples/WEB-INF/servlets.

The user interface is shown below:

The HTML code for this page, BabyGame1.html, is stored in <jswdk-root>/examples/jsp/pageview/ and includes a form that prompts a user for selections. The user is asked to make some guesses about the statistics of a baby to be born in the near future. The HTML code is as follows:

<html>
<head>
<title>Baby Game</title>
</head>
<body bgcolor="#FFFFFF">
<form method="post" action="BabyGame1.jsp" name="">
<center>
<h3>
Baby Game</h3></center>

<center>
<br>
<table BORDER COLS=5 WIDTH="75%" >
<caption>Please enter your own name:
<input type="text" name="guesser"></caption>

<tr>

<td>
<br><input type="radio" name="gender" value="Female" checked>Female
<p><input type="radio" name="gender" value="Male">Male
<p></td>

<td><font size=-1>Please choose a date:</font>
<p>Month: <select name="month">
<option value="January">January</option>
<option value="February">February</option>
...
<option value="December">December</option>
<br></select>
<p>Day: <select name="day">
<option value="1">1</option>
<option value="2">2</option>
...
<option value="31">31</option>

<br></select>
<p> </td>

<td><font size=-1>Please choose a weight:</font>
<p>Pounds: <select name="pounds">
<option value="5">5</option>
<option value="6">6</option>
...
<option value="12">12</option>
<br></select>
<p>Ounces: <select name="ounces">
<option value="1">1</option>
<option value="2">2</option>
...
<option value="15">15</option>

<br></select>
<p> </td>


<td><font size=-1>Please choose a length:</font>
<p>Inches: <select name="length">

<option value="14">14</option>
<option value="15">15</option>
...
<option value="25">25</option>

</select><p> <p> <p> </td>

</tr>
</table>
</center>

<br> 
<center>
<p><input type="submit" name="submit" value="Make Guess">
          
<input type="reset" name="reset" value="Reset">
</center>

<br></form>
</body>
</html>

Continued...


NEXT PAGE



7 RELATED COURSES AVAILABLE
INTRODUCTION TO JAVA PROGRAMMING
The aims of this Java training courses is to understand the role that Java plays on the Internet; describe the be....
JAVA (V1.2): ADVANCED PROGRAMMING
This course teaches the reader to learn, understand and become familiar with the advanced features of Java progra....
INTRODUCTION TO JAVABEANS
To go from the fundamentals of JavaBeans programming to the threshold of Advanced level. Gaining in depth progr....
C++ PROGRAMMING
Object oriented programming is fast becoming the leading software design methodology, with C++ becoming ever more....
C PROGRAMMING
This course is design to provide non-C programmers with the essential skills and knowledge necessary to allow the....
 
1 RELATED JOBS AVAILABLE
JAVA DEVELOPER MANCHESTER
Computer Futures Solutions are seeking a Senior Java Developer for their Manchester based client. You will be joi....
CONTACT US
Thursday 24th July 2008  © COPYRIGHT 2008 - VISUALSOFT