Use struts, ibaits, and JSTL to develop a simple and common file upload system
File Upload is also a common problem. Struts provides a convenient File Upload Component. Using struts, you can easily develop a file upload system. This article combines ibatis and JSTL to develop a simple and common file upload system. Through this article, you can learn how to configure the file upload function in struts, configure and use the dynamic form of struts1.1, if ibatis is simple to use, if JSTL is simple to use.
First, add a sentence to struts-config to specify the temporary directory and limit the size.
<Controller maxFileSize = "2 M" tempDir = "d:/temp"/>
Then, you only need to add enctype = "multipart/form-data" in form to implement struts upload. Is it very easy?
Create a table in the database.
Create sequence Attachment_seq;
Drop table attachment;
Create table Attachment
(
AttachID INT not null, -- auto-increment number AttachFilename VARCHAR2 (250) null, -- file name AttachFileSize INT not null, -- file size AttachMimeType VARCHAR2 (70) null, -- file type AttachDesc VARCHAR2 (250) null, -- Description AttachCreationIP VARCHAR2 (20) not null, -- uploaded IP AttachCreationDate TIMESTAMP not null, -- Creation Time AttachModifiedDate TIMESTAMP not null, -- file storage path ATTACHFILEPATH VARCHAR2 (250) not null,
Primary key (AttachID)
);
Create or replace trigger Attach_trig_autoinc
Before insert on Attachment
For each row
Begin
If (: new. AttachID is null) then
Select Attachment_seq.nextval into: new. AttachID from dual;
End if;
End;
The field content is very simple.
Create an ibatis SQL map file. Create Standard insert, update, delete, and find SQL statements. I believe that my friends who have read the previous series of articles are familiar with this.
<? Xml version = "1.0" encoding = "UTF-8"?> <! DOCTYPE SQL-mapPUBLIC "-// iBATIS.com//DTD SQL Map 1.0 // EN "" http://www.ibatis.com/dtd/sql-map.dtd ";> <SQL-map name =" attachment "> <! -- ===================================================== ======= Mapped-statement insert ================================== ===================--> <dynamic-mapped-statement name = "insertattachmentDao"> insert into ATTACHMENT (<dynamic prepend = ""> <isPropertyAvailable prepend = ", "property =" ATTACHID "> <isNotNull prepend =" "property =" ATTACHID "> ATTACHID </isNotNull> </isPropertyAvailable> <isPropertyAvailable prepend = ", "property =" ATTACHFILENAME "> <isNotNull prepend =" "property =" ATTACHFILENAME "> ATTACHFILENAME </isNotNull> </isPropertyAvailable> <isPropertyAvailable prepend = ", "property =" ATTACHFILEPATH "> <isNotNull prepend =" "property =" ATTACHFILEPATH "> ATTACHFILEPATH </isNotNull> </isPropertyAvailable> <isPropertyAvailable prepend = ", "property =" ATTACHFILESIZE "> <isNotNull prepend =" "property =" ATTACHFILESIZE "> ATTACHFILESIZE </isNotNull> </isPropertyAvailable> <isPropertyAvailable prepend = ", "property =" ATTACHMIMETYPE "> <isNotNull prepend =" "property =" ATTACHMIMETYPE "> ATTACHMIMETYPE </isNotNull> </isPropertyAvailable> <isPropertyAvailable prepend = ", "property =" ATTACHDESC "> <isNotNull prepend =" "property =" ATTACHDESC "> ATTACHDESC </isNotNull> </isPropertyAvailable> <isPropertyAvailable prepend = ", "property =" ATTACHCREATIONIP "> <isNotNull prepend =" "property =" ATTACHCREATIONIP "> ATTACHCREATIONIP </isNotNull> </isPropertyAvailable> <isPropertyAvailable prepend = ", "property =" ATTACHCREATIONDATE "> <isNotNull prepend =" "property =" ATTACHCREATIONDATE "> ATTACHCREATIONDATE </isNotNull> </isPropertyAvailable> <isPropertyAvailable prepend = ", "property =" ATTACHMODIFIEDDATE "> <isNotNull prepend =" "property =" ATTACHMODIFIEDDATE "> ATTACHMODIFIEDDATE </isNotNull> </isPropertyAvailable> </dynamic>) valueS (