|
|||
Like ASP, JSP also need a third party library to do this. Do take a look at this
http://www.jguru.com/faq/view.jsp?EID=160
__________________
Venzon Solution Services |
|
|||
Jakarta Commons FileUpload.
Hi lcf,
I strongly suggests the Jakarta Commons FileUpload. http://jakarta.apache.org/commons/fileupload/ The input form has to be "multipart/form-data" as follows: Code:
<form action="/products/addCategory.jsp?action=submit&processFlowToken=<c:out value="${requestScope.processFlowToken}" />" method="post" enctype="multipart/form-data" name="frm_Product">
Put the .jar into your library. Below are some of the key codes you'll be using in your java class. Code:
import org.apache.commons.fileupload.*;
...
...
DiskFileUpload upload = new DiskFileUpload();
if ( upload.isMultipartContent(req) ) {
List items = upload.parseRequest(req);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if ( item.isFormField() ) {
// process normal input form fields
System.out.println("Field: " + item.getFieldName() );
System.out.println("Value: " + item.getString() );
} else {
// process uploaded fields.
File fullFile = new File( item.getName() );
// finding the physical directory the image is going to be stored at
String dirPath = getServletContext().getRealPath("/products/images/");
// just my own little modification to the uploaded image filename.
String fileName = trimImgFileName(fullFile.getName(), item.getFieldName(), nextId);
// writing the image file
item.write( new File( dirPath, fileName ) );
}
}
}
...
...
private String trimImgFileName(String fileName, String fieldName, String nextId) {
StringBuffer sb = new StringBuffer(fileName);
sb.replace(0, sb.lastIndexOf("."), nextId + "_" + fieldName);
return sb.toString();
}
I'm just extracting a few key areas I suggest you'd look at. I hope I'm not confusing u. |
![]() |
«
Previous Thread
|
Next Thread
»
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to create a form which allow people to upload their images? | eyeball | Website Design | 8 | 02-08-2005 12:42 PM |
| Need a custom toolbar??? | besttoolbars | Other Webmaster-related Services and Promotion | 0 | 27-08-2004 03:33 PM |
| Custom toolbar? Easy! | besttoolbars | Other Webmaster-related Services and Promotion | 0 | 24-06-2004 03:59 PM |
| Create a custom IE toolbar! | besttoolbars | Other Webmaster-related Services and Promotion | 0 | 27-05-2004 06:37 PM |
| Custom Web Hosting Package? | lcf | Other Webmaster-related Services and Promotion | 5 | 15-07-2003 09:14 AM |
All times are GMT +8. The time now is 03:20 AM.
Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.













Linear Mode

