TOC PREV NEXT INDEX



Respond to database query


Now you must add some additional code so your Servlet responds appropriately to the results it gets. Add the following code to the bottom of the doGet area:

if (tableData.length > 0) {
yourSales = "<P>Your year to date sales are "
+tableData[0][1]+"!";
} else {
yourSales = "<P>You are <I>not</I> one of our "+
"sales people.";
}
out.println(yourSales);

Next you will use the Code Sourcerer to generate the code to close the output stream. While the output stream will eventually be closed on its own, closing it manually can make your Servlets more responsive.

  1. Press the 'Code Sourcerer' button.
  2. Choose 'Servlet Operations' and press Next.
  3. Choose 'Close the output stream...' and press Next.
  4. Press Done to use 'out', the name you have given the output stream. The Code Sourcerer will generate the following line of code.
out.close();

You can now test your work. The Pointbase database server should have already been started.

  1. Choose 'Save' from the File menu to save your work.
  2. Choose 'Initialize Class' from the Program menu.
  3. Choose 'Execute init' from the Program menu to force your servlet to run its init code. This is important because this is where your servlet will connect to the database.
  4. Go back to the IDE without closing the Servlet Composer.
  5. Open the html file you created earlier, NameForm.html, from the IDE. Your browser should open to the form page you created.
  6. In your browser, try typing a name and press the 'Send' button.

See what happens when you type "Carl" or "Fred".

You have finished creating a Servlet which queries a database and uses the information to dynamically create HTML which is returned to a user.

If you wish to stop here, save your work and exit Simplicity and PointBase. To resume the tutorial, you must start Simplicity Professional, then open the Tutorial7 project in Simplicity. Open the Response HttpServlet.Re-start the Pointbase database server.


Data Representations, Inc.
http://www.datarepresentations.com
support@datarepresentations.com
sales@datarepresentations.com
TOC PREV NEXT INDEX