Also I needed something like this for internal affairs inside our institute, so I added some specific, though general-purpose, functionalities.
The main features are :
I will now describe the functionality of the servlet, starting from the look and feel of a typical screen. As explained in the next section typically one will have a frameset with two frames, the upper one used for login, and the lower one for the output. I show only the lower one, since the upper one has a look which depends on the way you build your site !
The typical page for a non-guest user will look like this, with a top "keyboard" (an HTML table with several buttons and control) followed by the display of the database table (the latter can be quite long and require scrolling with the browser scroll bar).
The buttons and links in the above table are disabled, with the exception of the numbered links in the first (green) column labelled "seq". Clicking on them will show you what the record looks like when opened for edit. Click on the "Dont" button to close the record and return.
The above sample demonstrates also the typical cell colour coding.
For a guest user the top "keyboard" will have some functions disabled (additionally the "Display" panel can be disabled if the table does not contain a status column, irrespective of the user) as shown below.
Below I will explain :
type | support | look in display mode | look in edit mode | ||
---|---|---|---|---|---|
auto increment | special | 13 | URL on green | couple of buttons, the second can be Save or Add according to editing mode | |
editor column | special | manuzio | italic red on default | editing... duplicating... adding new... |
message depending on editing mode, direct editing not allowed |
boolean | planned | T | white on blue | n/a | currently unsupported |
byte | planned | 64 | darker cyan | n/a | currently unsupported |
short | planned | 256 | dark cyan | n/a | currently unsupported |
long | yes | 1024 | cyan | ||
float | yes | 1.0 | dark orange | text area | |
double | planned | 2.0 | orange | n/a | currently unsupported |
string | yes | xyzzy | default | text area | |
date | yes | 1492-10-12 | italics on light yellow | text area | |
time | planned | 09:30:05 | italics on yellow | n/a | currently unsupported |
timestamp | yes | 2006-01-11 17:05:53.0 | italic red on default | editing... duplicating... adding new... |
message depending on editing mode, direct editing not allowed |
enumeration | yes | forse che si | white | menu with ENUM allowed values | |
set | planned | big,bad | gray | TBD | currently unsupported |
anything else | no | UNSUPPORTED TYPE | message on red | unchanged | editing not possible |
There is no syntactic check on the value input in a text area (besides the implicit
ones for menus or for fields like timestamp or editor which are generated internally).
The rare case when mysql error messages are generated, typically because of incorrect
editing, they will appear in red, and should be recoverable in a self-understandable way.
Note however that inputting invalid values in most cases does not generate an error,
but the insertion of a null or default value in a cell. Thus, you'd better verify the
content of an edited record after editing.
|
The example shown indicates that we have requested to hide the last three
columns, and to sort in ascending order on columns (in this order) anint,editor,seq,flag.
Note that sorting on an hidden column is allowed.
The request will be processed as soon as the user clicks on one of the
"Apply choices ..." buttons.
Note that some special columns cannot be hidden.
The top three buttons (outside of the table with the column list) are used as follows:
The meaning of the radio buttons in the table with the column list should be self
explanatory (sorting can occur in ascending or descending order).
The numbered menu is used instead as a sequence number to select the priority in which the columns selected
for sorting are used. It is set to blank for unsorted columns, and remembers the
previous value for sorted columns. However if all columns are unsorted, it assumes
the default order of the column in the table.
If you click on Asc or Desc to sort an unsorted column and leave the
sequence number blank, such columns will be sorted last.
If you assign the same sequence number to more columns, they will be sequenced in
alphabetic order of the name.
The other functions of the top keyboard are as follows :
Note that an edited record once closed will appear in the display in the
position corresponding to the table sorting criteria (or last if none), not
necessarily close to where it was before !
Note also that edited record are always assigned an updated timestamp (if
a timestamp column is present), an updated "editor signature" (if an editor
column is present) and a new sequence number (if the record has been duplicated
or added), without interaction with or control of the user.
Note that the extra condition is remembered, but is not displayed !
The Reset button will not clear the remembered condition,
but just, hopefully, clear the entire form ... hopefully, because with a form
using javascripts and dynamic content, one never knows.
Note that also the limits are remembered, but not displayed !
In addition I use as servlet environment jsdk2.1 (whose server.jar and servlet.jar
shall be prepended to the CLASSPATH).
In addition again I use as JDBC mm.mysql.jdbc-1.2c (whose org directory shall
also be prepended to the CLASSPATH).
To install the servlet
If you want to experiment with other java stuff you are welcome to do so, but
you will be rolling on your own. Eventually keep me posted.
It allows to select for display only the records whose status is
not Retired, not Deleted or Active (other values
are not considered, use extra condition below).
Click on "Any" to display all records.
After clicking on a radio button do not forget to Apply it.
After clicking on a radio button do not forget to Apply it.
... and do not forget in which editing mode you are !
No further confirmation is requested, so use with care !
Such condition is implicitly ANDed with other implicit conditions (e.g.
those from the "Display" panel).
After entering a condition do not forget to Apply it.
In case of doubt reset it entering a blank condition and pressing
Apply. This will get rid of the condition altogether.
The only difference with the mysql LIMIT clause is that this one
works from and to a (relative) position and not "offset and for" like
native mysql (which is less natural, I'm a real (Fortran) programmer and
never count from zero to nine fingers).
Both limits shall be entered, if one is left empty, limits are reset.
After entering a condition do not forget to Apply it.
In case of doubt reset then entering blank values and pressing
Apply. This will get rid of the limits altogether.
How to build a web page calling the servlet
You can access any database table, or family of tables (in a mysql database which you
are entitled to access) building just two web pages (at least, I do it with two) :
<FRAMESET ROWS="10%,*" BORDER=0>
<FRAME SRC="login.html" NAME=UP MARGINWIDTH=0 MARGINHEIGHT=0>
<FRAME SRC="blank.html" NAME=DOWN>
</FRAMESET>
The aesthetics and the frame names are optional (in rhis colour),
what matters is that you have two frames and that they are named UP and DOWN (the latter
taking most of the screen). The top frame is initialized with the login page
described below, while the bottom frame is initialized with anything (I use a
blank.html file containing a single i.e. a
non-breaking space ... OK, so I do work with three web pages).
The bottom frame is where the servlet will display its output.
<FORM method=POST action="http://yourhost:8080/servlet/mysqlservlet"" target="DOWN">
<INPUT TYPE=HIDDEN NAME="mysqlhost" VALUE="localhost">
<INPUT TYPE=HIDDEN NAME="mysqldb" VALUE="dbname">
<INPUT TYPE=HIDDEN NAME="mysqluser" VALUE="anusername">
<INPUT TYPE=HIDDEN NAME="mysqlpwd" VALUE="optional">
<INPUT TYPE=HIDDEN NAME="source" >
Table: <SELECT NAME="mysqltable">
<OPTION VALUE="sample">sample
<OPTION VALUE="test">test
</SELECT>
<INPUT TYPE=HIDDEN NAME="seqColumn" VALUE="seq">
<INPUT TYPE=HIDDEN NAME="timeColumn" VALUE="modified">
<INPUT TYPE=HIDDEN NAME="statusColumn" VALUE="status">
<INPUT TYPE=HIDDEN NAME="editorColumn" VALUE="editor">
Username:
<INPUT type="text" size=8 maxlength=8 name="editor" value="guest" >
<INPUT TYPE=SUBMIT VALUE="Login" onclick=this.form.source.value="login">
<INPUT TYPE=SUBMIT VALUE="Logout" onclick=this.form.source.value="logout">
(to change table please logout and login again)
</FORM>
i.e. as a form whose action is the path to the servlet (you shall
insert your hostname here), and whose other controls are explained below.
But you might want to read it from a form.
There is a special value of guest : when the editor is guest,
editing of the mysql tables is disabled, and the user can only browse
existing tables but not edit their records.
The column in the table should be a CHAR or VARCHAR typically of 8 characters.
The absence of such a column (or setting statusColumn to none)
inhibits physical deletions of files from a table
If your form points (explicitly or implicitly) to a column not existing
in the table, editing will be disabled.
S/W requisites
I have developed and tested the servlet under Linux SuSE 9.2, using as
Java compiler and runtime environment to be specified in the CLASSPATH (j2ee.jar)
the version j2ee-1.4.
Good luck !
Getting the s/w
The source code for the servlet is available in file
mysqlservlet.java.
The documentation is represented by the current page.