
| Task ID | Title | Task Type | Points | Due |
|---|---|---|---|---|
| image | ImageUpload | ![]() | 4 | TBA |
These are the source and class files for your application. (To save them to your hard drive use <RIGHT CLICK>Save Target As ...
The following links show this application running in the fontanini context website.
|
CREATE TABLE image ( imageid INT(6) DEFAULT '0' NOT NULL AUTO_INCREMENT PRIMARY KEY, filesuffix CHAR(4), description VARCHAR(80), width SMALLINT, height SMALLINT, userid CHAR(10) NOT NULL, datestamp DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL); |
The DATETIME type is used when you need values that contain both date and time information. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.
The TIMESTAMP column type provides a type that you can use to automatically mark INSERT or UPDATE operations with the current date and time. We will not use this since we want the date-time of the original file upload and not the date-time of the last UPDATE operation.
You can obtain the current date and time using this code:
|
// Format the current time // using the timezone of webappcabaret.com PDT SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss"); String dateString = formatter.format(new Date()); |
The imageid is generated automatically each time a row is inserted into the image table. Note that the imageid is not explicitly inserted into the record. It is assigned automatically.
After inserting the image data into the table, your application must find out the imageid. This imageid will become the name of the file that is saved into the /upload directory (instead of the hard-coded example "1234").
Here is how to obtain the imageid value which was assigned by MySQL during the last INSERT query.
| <%=((org.gjt.mm.mysql.Statement)stmt1).getLastInsertID()%> |
An explanation follows: If the DBTAGS statement id is "stmt1", <sql:statement id="stmt1"... , this corresponds to a variable named stmt1 which is a JDBC Statement object. This Statement object is actually an instance of a Mark Matthews driver subclass org.gjt.mm.mysql.Statement. By casting the statement to that class, we can call the method getLastInsertID() which is a MySQL method, not provided in the standard JDBC API.
Uploaded images are saved in the /upload directory with the file name the same as the auto_increment value of imageid. The file name must have a file suffix corresponding to the type of image uploaded (.gif, .jpg .png)
If an error occurs, print an error page with a suitable message. The user
can use
their browser "BACK" button to return to the form, but the error page
should also provide a link back to index.jsp.
After uploading the image, show the image information.
To avoid needless duplication of code, do this by using the JSP
directive for run-time page include:
<jsp:include page="view.jsp" flush="true" >
Description will have a hypertext link to view.jsp This hypertext link will use a query string ?id=1234 to identify the imageid. view.jsp will fetch any other information it needs directly from the image table using the id value.
If Description is null, substitute Unknown so there will be some text for the hypertext link.
The image tag must have the following IMG attributes: