Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Struts
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Liutauras Vilda
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Struts
File Upload
DVVN Sudhakara Rao
Greenhorn
Posts: 17
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I have a applicaiton using
struts
. In my
jsp
page I want to give the users option to upload a Image/emotoicon. Can any body guide me how can we achieve it?
Sujatha Kumar
Ranch Hand
Posts: 134
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
This is how you do it..
In your jsp
<tr> <td width="285" class="TextFontBold" align="left"><bean:message key="configure.label.filepath"/></td> <td width="697" class="SmallTextFont"> <html:file property="theFile" size="24"/> </td> </tr>
In your Form
private FormFile theFile =null public void setTheFile(FormFile theFile ) { this.theFile = theFile ; } public FormFile getTheFile() { return this.theFile; }
In your Action
public void doUpload(String path,FormFile file) throws Exception { try { String fileName = file.getFileName() ; int fileSize = file.getFileSize() ; if ( (fileName != null) && (!fileName.equals("")) ) { if (fileSize != 0) { File newFile = new File(path+File.separator +fileName) ; FileOutputStream fos ; fos = new FileOutputStream(newFile) ; byte[] fileData = file.getFileData() ; fos.write(fileData) ; fos.close() ; } } } catch(Exception e) { throw e; } }
SCJP,SCWCD,SCBCD,SCEA Part I
fabiano cruz
Greenhorn
Posts: 1
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hi Sujatha,
how to get the server's path you are uploading the file to?
thks
fabiano
Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
doPut()????
HTTPS File Uploader
Images is too big....
How can I upload a File using Struts
Uploads rights, how long
More...