Database-served Web Pages

Static version

There are various reasons for serving the content of your documentation from a database. For example, you may have some content that should only be accessible to some of your users. You could handle this content with a conditionalization tag library, but you could also handle it by using a database system's built-in access restrictions. Handling this particular issue with a database may make it easier to make a particular topic more or less restrictive.

You may also work in a collaborative environment with other writers. In fact, you may already have a database system set up to handle content management, and would like to deliver your documentation from within that existing database system. If you have access to the database schema, you may be able to save yourself a step if you don't have to export your content to update your documentation.

I have created a version of this particular page that is served from a MySQL database, to enable you to “play” with this feature to see how you can use a database to restrict users to content to which they have appropriate access level to view. In this database-served version of this page, I have added each sentence as a database record. I have also enabled you to choose a color for each sentence, which you might want to use to indicate to your user that the color-coded sentence is privileged information.

Database Schema

The following is the database schema for the table that stores the content shown on this page.

userName—20-character string that stores a username that you specify. When you move from this static page into the demo, a copy of the master table is copied, and the userName is set to the user name you specify. This allows more than one visitor to this web site to modify the content at the same time, without affecting the other visitors.

pageName—50-character string that stores the name of the page and some or all of its path.

paragraphNum—An integer that indicates which paragraph the sentence belongs to.

sentenceNum—An integer that indicates the sentence’s location within a paragraph.

sentence—A string that holds the content of the sentence.

accessLevel—An integer between 1 and 5, where 1 indicates no restriction on the content, and 5 is the most restrictive.

displayColor—A boolean value that indicates if the sentence should be displayed in color. When set to false, the sentence will be displayed in the default color. When set to true, the sentence will be displayed in color depending on its accessLevel value: 1 = brown, 2 = purple, 3 = green, 4 = blue, and 5 = red.

Files Used for this Functionality

For you to modify the database records that make up this demo, I needed to add a couple of extra ancillary web pages. The following is a complete list of files that I implemented for this demo:

dbs_live.jsp—This is the version of this page that is served from a database.

dbs_setvalues.jsp, dbs_setvalues2.jsp, dbs_setvalues3.jsp, dbs_setvalues4.jsp—These pages let you specify the accessLevel and displayColor attributes for individual sentences that make up this page.

dbs_login.jsp—This page lets you set the access level of the viewer, before viewing the page databaseservedpages_live.jsp. You can return to this page to move the access level up or down as desired.

_dbs_login.jsp—This is a page that actually records the access level you specified on the main login page.

Note that only the file dbs_live.jsp is served from a database (though others do interact with the database).

JSP Source

Click any of the following links to display the source for the corresponding files.

  • dbs_live.jsp

  • dbs_setvalues.jsp

  • _dbs_setvalues.jsp

  • dbs_login.jsp

  • _dbs_login.jsp

Let’s Go!

Now that you have had a chance to see the database schema for the database-served page, the pages that you will visit to modify the database content, and the JSP source for those pages, you can start playing around with the feature. The first step is to modify the database.

Page last modified 06/15/2002