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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Struts
setTheFile method is not called using FormFile in Struts 1 and GlassFish 3.1.2
thida htun
Greenhorn
Posts: 1
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I have problem in uploading multiple files using
Struts
1.3.10. setTheFile method is not calling and list size get 0. I didn't get any exception.
Looking forward to your suggestion.
Here is my code
ActionForm code:
public class UploadForm extends ActionForm { private FormFile theFile; private List listFile; private int index=0; public List getListFile() { return listFile; } public void setListFile(FormFile theFile) { listFile.add(index, theFile); } public int getIndex() { return index; } public void setIndex(int index) { this.index = index; } public void initFileList() { listFile=new ArrayList(); this.index=0; } public FormFile getTheFile(int index) { return this.theFile; } public void setTheFile(int index,FormFile theFile ) { System.out.println("setter"); this.theFile=theFile; setListFile(theFile); this.index++; } }
Action Code:
public ActionForward uploadMultiple(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { try{ UploadForm myform=(UploadForm)form; myform.initFileList(); List al=myform.getListFile(); System.out.println("Size of Array List:" + al.size()); //create the upload folder if not exists File folder = new File("C:\\upload"); if(!folder.exists()){ folder.mkdir(); } for(int i=0;i<al.size();i++){ // get file from the bean FormFile ff = (FormFile) al.get(i); String fname = ff.getFileName(); if(fname.length()==0) { continue; } System.out.println("File Name :" + fname); System.out.println("File Name length:" + fname.length()); System.out.println("file type:" + ff.getContentType()); // save file in the app server if(!("").equals(fname)){ File newFile=new File("C:\\upload\\"+fname); if(!newFile.exists()){ FileOutputStream fos = new FileOutputStream(newFile); fos.write(ff.getFileData()); fos.close(); } request.setAttribute("fileName["+i+"]",fname); } } request.setAttribute("filePath", folder.getAbsolutePath()); } catch(Exception e) { System.out.println("Exception in uploadAction"+e); } return mapping.findForward("success"); }
JSP
Code:
<html:form action="/maintain/uploadFiles?method=uploadMultiple" enctype="multipart/form-data" method="POST"> <div id="content"> <div id="fileSection"> Select file to upload <html:file property="theFile[0]" /><br> </div> <html:button property="bt" onclick="addElement()">Upload More files</html:button> <input type="submit" value="Save" /> </div> </html:form>
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Struts Formfile Not Getting instantiated, <html:file property="theFile"/> sets to null
File Upload
Problem with file separator
Map the action form object
Displaying file content in a jsp page
More...