Pictures, word,text files cannot be stored as VARCHAR2 types in the database, and are stored in orca in Clob,blob type. stored in SQL Server as a img,txt type. The advantage of storing attachments in the database is that attachments are not easily lost, But it's a little inconvenient to write to the database and read it out. Are you sure you want to store the attachment in the database?
The relative address of the attachment can be stored in the database. The attachment is really saved in the file system. It's easy to read:
Under the MyProject project, under Webroot, there is a catalog picture specifically for storing pictures
There is a field in the database Tpath store relative paths such as: String rpath=/picture/mypicture20070905.jpg
In JSP:
<a href= "<%url%>" ></a>//can be displayed
<a href= "<%world Document relative path%>" > Attachment a </a>//Click the right button to save to download
How to upload attachments to the Web server picture directory
Diskfileupload fu = new Diskfileupload ();
Fu.setsizemax (10000000);
Fu.setsizethreshold (4096);
List Fileitems = fu.parserequest (request);
Iterator iter = Fileitems.iterator ();
while (Iter.hasnext ()) {
Fileitem item = (Fileitem) iter.next (); Item.isformfield () ignores any other form information that is a file field
if (!item.isformfield ()) {
String name = Item.getname ();
Long size = Item.getsize ();
if (name==null| | Name.equals ("")) && size==0)
Continue
String Mpath=application.getrealpath ("/picture")//Get current page absolute path
String fileseparator=system.getproperty ("File.separator");
Item.write (New Java.io.File (MPath + fileseparator+rname));//The Web server absolute path to the picture
}