URGENT: Is it possible to upload multiple files using STRUTS

Hi,
Is it possible to upload multiple files using STRUTS.
I am able to upload a single file. But how do i upload multiple files ??
upload.jsp
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html:html>
<head>
<title>New Page 1</title>
</head>
<body>
<html:form action="/secure/uploadFile.do" enctype="multipart/form-data" method="POST" type="com.smartstream.webconnect.user.actions.UploadActionForm">
<p>File to upload
<html:file property="fileUpload" size="20"/></p>
<p><html:submit/></p>
</html:form>
</body>
</html:html>
UploadAction.java
public class UploadAction extends BaseAction {
    Logger log = Logger.getLogger(AttachMessageAction.class);
    public ActionForward executeAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ActionException {
        System.out.println("executeAction of UploadAction");
        UploadActionForm uploadActionForm = (UploadActionForm) form;
        int fileSize = uploadActionForm.getFileUpload().getFileSize();
        System.out.println("uploadActionForm.getFileUpload().getFileSize() = " + uploadActionForm.getFileUpload().getFileSize());
        byte buffer[] = new byte[1024];
        try {
            BufferedInputStream bufferedInputStream = new BufferedInputStream(uploadActionForm.getFileUpload().getInputStream());
            FileOutputStream fos = new FileOutputStream("s:\\uploaded\\" + uploadActionForm.getFileUpload().getFileName());
            int read;
            while ( (read = bufferedInputStream.read(buffer,0,buffer.length)) != -1) {
                fos.write(buffer, 0, read);
            fos.flush();
            fos.close();
            bufferedInputStream.close();
            return mapping.findForward("success");
        } catch (IOException e) {
            e.printStackTrace();
            return mapping.findForward("error");
        }catch(OutOfMemoryError o){
            o.printStackTrace();
            System.out.println("o.getMessage() " + o.getMessage());
            return mapping.findForward("error");
UploadActionForm.java
public class UploadActionForm extends ActionForm{
    private FormFile fileUpload;
    private byte[] fileContent;
    public FormFile getFileUpload() {
        org.apache.struts.taglib.html.FormTag _jspx_th_html_form_0;
        return fileUpload;
    public byte[] getFileContent() {
        return fileContent;
    public void setFileUpload(FormFile fileUpload) {
        this.fileUpload = fileUpload;
    public void setFileContent(byte[] fileContent) {
        this.fileContent = fileContent;
}--Bhupendra Mahajan

Yes, you could try using the multipart handler...
But I have a better idea...
Determine the maximum number of file uploads that the
user can do at one time. I mean, you can't
realistically have the user upload a million files at
one time. So say the max is 20. So you create your
action form class with 20 FormFile fields called file1
to file20.
Then when you dynamically create your page, you
dynamically create the specified number of file fields
and 1 hidden field called "totalFiles" which contains
the number of file fields you created. This should be
an int field in the form bean.
Then when you do your action processing, you just loop
thru the totalFiles... Or well, actually, you may not
need that at all. You could just check all the
FormFile fields and whatever ones aren't null contain
files.But what about UploadActionForm.java[b]
How do i have exact mapping of the HTML form in this file ??
--[b]Bhupendra Mahajan

Similar Messages

  • How to upload multiple files using af:inputfile

    Hi,
    I am using J dev 11.1.1.3. I have a requirement wherein i need to upload multiple files using af:inputfile. Can we do in it ADF ? Is there any other work around to implement the same. I have checked previous questions but not able to find proper solution for this.
    Any pointer in this regard is highly helpful.
    Regards,
    Kalyan

    You have to do this your self by either (as vinod said) using a different component (not present in adf) or implementing this:
    1) allow the user to select multiple filenames (somehow)
    2) zip them together
    3) upload the zip
    4) unpack the zip on the server
    5) work with the files
    Timo

  • How to upload multiple files using wicket

    Hai,
    how to upload multiple files using wicket at a single browse.
    any suggestion?
    Thanks in advance

    You have to do this your self by either (as vinod said) using a different component (not present in adf) or implementing this:
    1) allow the user to select multiple filenames (somehow)
    2) zip them together
    3) upload the zip
    4) unpack the zip on the server
    5) work with the files
    Timo

  • Upload multiple file using csom

    how to upload multiple files programmatically using csom and store in sharepoint list
    Blitz

    Hi,
    I have seen a similar post from you, you want to upload multiple file using csom.
    You can take a look at the following thread:
    http://social.msdn.microsoft.com/Forums/en-US/edd3bd86-417b-4174-9627-5a714c733256/upload-multiple-files-using-client-context-object-model?forum=sharepointdevelopment
    I would suggest you to open only single thread for single issue. You can discuss your problem in the above thread only.
    Thank you for your understanding and support.
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • Is it possible to upload multiple files at the same time?

    Hi folks,
    It seems pretty trivial to implement a file upload item, but is there some way to allow selection (upload) of multiple files at the same time? Seems like this has probably come up before, but I didn't find much for solutions in my search. Any links or insight would be appreciated.
    Thanks!
    -Adam vonNieda

    Thank you both for your replies.
    @Manish - That does allow for multiple file uploads without refreshing the page, but does not allow for multiple file uploads at the same time.
    @Tony - That might be the way I end up going, although I probably should have been more specific. It would be really nice it there was a way to do a mutli-file select using the control or shift button like you can with a standard file selection dialog (if you want to copy multiple files, for example). Having a separate line for each file browser means there has to be a limit on the number that can be selected at the same time.
    Has anyone implemented a method of selecting multiple files at once, and hitting an upload button once to get them into the database?
    Thanks again Manish and Tony, very helpful.
    -Adam

  • Upload multiple files using lsmw

    I have to upload 2 different files using lsmw..
    Please explain me the procedure..
    I made the option as sequential file in specified files..
    but i am getting error.. Using different sequential files is not allowed...

    is der some problem or just u need clarification?
    When I import the data everything seems fine... 52 entries from file 1, and 682 entries from file 2.
    In my "Fieldmapping and conversion rules" i have a statement like this:
    read table FILE2 with key oldsls = FILE1-lgart.
    My problem is that FILE2 is empty, even that I saw in my import screen that 682 entries was imported.
    in one statement, you are saying ki it seems fine then u r saying that ur file 2 is empty. HOW CAN U UPLOAD DATA FROM AN EMPTY FILE ?
    and we don't don anything in field mappng until unless v don't use complex stuctures while uploading data. LSMW takes care of everything by itself.
    Most important thing is
    reward point
    hope this will help
    bye tc
    sandy
    waiting for reward point

  • How to upload the files using struts

    Hi all
    My requierment is to upload the files from the client machine and save it on the server, the file size must not increase more than 250 MB and to validate that we cannot do validation on the client machine so we have to validate it on the server side. below is my code kindly go through it if there is any problem in Bussiness Logic
    1>Upload.jsp
    2>UploadForm.java
    3>UploadAction.java
    *1>Upload.jsp*
    <%@ page language="java"%>
    <%@ page import="java.io.*"%>
    <%@ taglib uri="/WEB-INF/struts-bean" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-html" prefix="html" %>
    <html>
    <body bgcolor="white">
    <form name="uploadForm" action="TestApplication/upload" method="post" enctype="multipart/form-data">
    <table>
    <tr>
    <td align="center" colspan="2">
    <font size="4">Please Enter the Following Details</font>
    </tr>
    <tr>
    <td align="left" colspan="2">
    <font color="red"></font>
    </tr>
    <tr>
    <td align="right">
    File Name
    </td>
    <td align="left">
    <input type="file"  name="theFile">
    </td>
    </tr>
    <tr>
    <td align="center" colspan="2">
    <input type="submit" value="UPLOAD">
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>*2>UploadForm.java*
    package com.MyPack.Datamatics;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.upload.FormFile;
    public class UploadForm extends ActionForm
         private static final long serialVersionUID = 1L;
    private FormFile theFile;
       public UploadForm(){}
       * @return Returns the theFile.
      public FormFile getThefile() {
        return theFile;
       * @param theFile The FormFile to set.
      public void setThefile(FormFile theFile) {
        this.theFile = theFile;
    } *3>UploadAction.java*
    package com.MyPack.Datamatics;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.upload.FormFile;
    public class UploadAction extends Action
      public ActionForward execute(
        ActionMapping am,
        ActionForm af,
        HttpServletRequest req,
        HttpServletResponse res) throws Exception{
         UploadForm myForm = (UploadForm)af;
            // Process the FormFile
            FormFile myFile = myForm.getThefile();
            String contentType = myFile.getContentType();
            String fileName    = myFile.getFileName();
              int fileSize       = myFile.getFileSize();
              String data="";
              try{
            java.io.InputStream fileData  = myFile.getInputStream();
             String path="E:/store";
              File f = new File(path);
              java.io.OutputStream outputStream = new FileOutputStream(f+"/"+fileName);
              int temp = 0;
              byte[] buffer = new byte[8192];
              temp = fileData.read(buffer, 0, 8192);
              while ((temp) != -1) {
              outputStream.write(buffer, 0, temp);
                   outputStream.close();
                   data = "file has beeb written to E:/store" + fileName;
                   fileData.close();
              catch (FileNotFoundException fnf)
              { System.out.println("Cannot Found the file");
               System.out.println(data);
              System.out.println("contentType: " + contentType);
             System.out.println("File Name: " + fileName);
             System.out.println("File Size: " + fileSize);
          return am.findForward("success");
    }Thanks in Advance

    [help link 1|http://www.roseindia.net/struts/strutsfileuploadandsave.shtml]
    [help link 2|http://www.roseindia.net/struts/strutsfileupload.shtml]

  • OneDrive upload multiple files ?

    Hello,
    It is possible to upload multiple files in onedrive(skydrive) using WL.upload ? I tried something but I always get an error like "element must be an html input element" or something like this.
    Thanks.

    Hello Calin,
    Not sure if you are developing with the OneDrive API, if it is you could post this issue to OneDrive development forum:
    https://social.msdn.microsoft.com/Forums/en-US/home?forum=onedriveapi
    Or if you using this API with a web application, you could post it to:
    http://forums.asp.net/
    The current forum you posted to is used to discuss and ask questions about .NET Framework Base Classes (BCL) such as Collections, I/O, Regigistry, Globalization, Reflection.
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Upload Multiple files in SQL * Loader in one session

    Dear all,
    I want to upload multiple files using SQL*Loader in one go. In Unix its very easy as I have a quite experience of that. Could any body tell what is a way in Windows to upload multiple files in one go while using SQL * Loader. I want to run that using DOS's Batch file.
    Thanks
    Ghulam

    In Unix its very easy like we are putting $ sign.
    sqlldr userid=?????/?????
    control="/u12/cad_delta.ctl",log="/u12/full_extract/$1",data="/u12/$1",bad="/u12//full_extract/$1",errors=500,silent=feedback
    Suggest for Windows? It should read all .DAT files of the Windows Folder.
    Thanks

  • How do you upload multiple files?

    Hi,
    This is propably an easy one.
    I am trying to upload multiple .gif files to a folder in KM.
    I went to Content Management -> KM Content and created a new folder inside a sub-folder.
    Now when I click on the contect menu I select New.. and then Upload...
    However, this only allows me to select for upload one file at a time.
    I neeed to upload about 50 files. It will take ages doing this one by one!
    Is there a quicker way?

    Hi
    Multiple upload of files is possible by using WEBDAV protocol.To use this follow the below steps.
    Go to folder to which u want to upload the files and the click on the context menu and select details.A new window will open up.In that select settings->properties->accesslinks.copy the WEBDAV link shown there.
    Now
    click My Network Places on your desktop, and choose Tools from the top menu bar/Map Network Drive from the context menu. If you donu2019t find My Network Places on your desktop you can find it under Windows Start menu option on your computer.
    select Sign up for online storage or connect to a network server. Click next
    Highlight Choose another network locations. Click next
    Use Cntrl+V to paste the URL path name(webdav URL).  Click next
    Change the URL location to the name of the folder in KM. Hit next.  Hit finish
    A folder by the name you just created will appear under my network places on your explorer application.
    Using this u can upload multiple files directly into folder u want.
    Hope this solves ur problem.
    Regards
    Hussain.

  • Uploading Multiple files in One-Click!!!

    Hi All,
    I have got nearly about 900 PDF files in my file server which need to be uploaded to the KM CONTENT Repository.
    what is the best methodology to upload all these file in to the repository in <u><b>one click.</b></u>
    Is it possible to achieve this??
    Eagerly waiting for replies.
    Regards,
    Kavitha

    Hi Patric,
    It is quite interesting to see that there is a way to upload multiple files in a click.
    I just followed your way. i copied the WebDAV URL and pasted and executed in a new browser. and i get....
    <i>The folder you are looking for has no displayable content.
    You can try one of the following:
    Access the folder using the Navigation user interface.
    Access the folder as a Web folder. Your operating system and browser dictate whether or not this will work.</i> "
    When i choose "Web Folder", i get a pop up and it says "<i>The web folder address Internet Explorer was given was too long. Please use a shorter address</i>."
    When i choose "Navigation User Interface", iam taken to the default KM Folder.
    I nowhere able to see the folder structure like what you have mentioned in your reply.
    Kindly help me out.
    Regards,
    Kavitha

  • How to upload multiple files

    Hi
    I am trying to create a form ,how can i provide a facility to upload more than 1 attachment
    Thanks in advance.

    Hi,
    I assume you mean uploading multiple files at once/in 1 action.
    As far as I know this is not possible out of the box, check http://apex-plugin.com/oracle-apex-plugins/item-plugin/multiple-file-upload_95.html for a plugin (based on HTML5) which enables you to do this.
    Regards
    Bas

  • Upload multiple files WITH correct pairs of form fields into Database

    In my form page, I would like to allow 3 files upload and 3 corresponding text fields, so that the filename and text description can be saved in database table in correct pair. Like this:
    INSERT INTO table1 (filename,desc) VALUES('photo1.jpg','happy day');
    INSERT INTO table1 (filename,desc) VALUES('photo2.jpg','fire camp');
    INSERT INTO table1 (filename,desc) VALUES('photo3.jpg','christmas night');
    However, using the commons fileupload, http://commons.apache.org/fileupload/, I don't know how to reconstruct my codes so that I can acheieve this result.
    if(item.isFormField()){
    }else{
    }I seems to be restricted from this structure.
    The jsp form page
    <input type="text" name="description1" value="" />
    <input type="file" name="sourcefile" value="" />
    <input type="text" name="description2" value="" />
    <input type="file" name="sourcefile" value="" />The Servlet file
    package Upload;
    import sql.*;
    import user.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.Map;
    import java.util.HashMap;
    import java.util.Date;
    import java.util.List;
    import java.util.Iterator;
    import java.io.File;
    import java.io.PrintWriter;
    import java.io.IOException;
    import java.text.SimpleDateFormat;
    import org.apache.commons.fileupload.servlet.ServletFileUpload;
    import org.apache.commons.fileupload.disk.DiskFileItemFactory;
    import org.apache.commons.fileupload.*;
    public class UploadFile extends HttpServlet {
    private String fs;
    private String category = null;
    private String realpath = null;
    public String imagepath = null;
    public PrintWriter out;
    private Map<String, String> formfield = new HashMap<String, String>();
      //Initialize global variables
      public void init(ServletConfig config, ServletContext context) throws ServletException {
        super.init(config);
      //Process the HTTP Post request
      public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        Thumbnail thumb = new Thumbnail();
        fs = System.getProperty("file.separator");
        this.SetImagePath();
         boolean isMultipart = ServletFileUpload.isMultipartContent(request);
         if(!isMultipart){
          out.print("not multiple part.");
         }else{
             FileItemFactory factory = new DiskFileItemFactory();
             ServletFileUpload upload = new ServletFileUpload(factory);
             List items = null;
             try{
                items = upload.parseRequest(request);
             } catch (FileUploadException e) {
                e.printStackTrace();
             Iterator itr = items.iterator();
             while (itr.hasNext()) {
               FileItem item = (FileItem) itr.next();
               if(item.isFormField()){
                  String formvalue = new String(item.getString().getBytes("ISO-8859-1"), "utf-8");
                  formfield.put(item.getFieldName(),formvalue);
                  out.println("Normal Form Field, ParaName:" + item.getFieldName() + ", ParaValue: " + formvalue + "<br/>");
               }else{
                 String itemName = item.getName();
                 String filename = GetTodayDate() + "-" + itemName;
                 try{
                   new File(this.imagepath + formfield.get("category")).mkdirs();
                   new File(this.imagepath + formfield.get("category")+fs+"thumbnails").mkdirs();
                   //Save the file to the destination path
                   File savedFile = new File(this.imagepath + formfield.get("category") + fs + filename);
                   item.write(savedFile);
                   thumb.Process(this.imagepath + formfield.get("category") +fs+ filename,this.imagepath + formfield.get("category") +fs+ "thumbnails" +fs+ filename, 25, 100);
                   DBConnection db = new DBConnection();
                   String sql = "SELECT id from category where name = '"+formfield.get("category")+"'";
                   db.SelectQuery(sql);
                    while(db.rs.next()){
                      int cat_id = db.rs.getInt("id");
                      sql = "INSERT INTO file (cat_id,filename,description) VALUES ("+cat_id+",'"+filename+"','"+formfield.get("description")+"')";
                      out.println(sql);
                      db.RunQuery(sql);
                 } catch (Exception e){
                    e.printStackTrace();
            HttpSession session = request.getSession();
            UserData k = (UserData)session.getAttribute("userdata");
            k.setMessage("File Upload successfully");
            response.sendRedirect("./Upload.jsp");
      //Get today date, it is a test, actually the current date can be retrieved from SQL
      public String GetTodayDate(){
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        String today = format.format(new Date());
        return today;
      //Set the current RealPath which the file calls for this file
      public void SetRealPath(){
        this.realpath = getServletConfig().getServletContext().getRealPath("/");
      public void SetImagePath(){
        this.SetRealPath();
        this.imagepath = this.realpath + "images" +fs;
    }Can anyone give me some code suggestion? Thx.

    When one hits the submit button - I then get a 404 page error.What is the apaches(?) error log saying? Mostly you get very useful information when looking into the error log!
    In any case you may look at how you are Uploading Multiple Files with mod_plsql.

  • How can I upload multiple files in a master detail relationship?

    I would like to be able to upload several files for one record (a one to many relationship). I tried using a master detail form, but the tabular form does not support file browse. I've searched the forum and found several examples asking how to upload multiple files at once. That is not what I'm trying to do. I simply want the user to browse, select a file, provide a file name and description. Then select the next file. When they are done selecting files (it may be one file or many files) I want them to hit the submit button and I'll run a procedure that saves the files to the database.
    How can I do this? Thanks, you guys are the best. Elizabeth

    Elizabeth,
    I had this situation come up once and here's what I did, thought it may not be exactly what you're looking for.
    I created a collection to store the ID's of the files that had been uploaded, along with the key and other information. The file browse input will upload your files into the wwv_flow_files table on submit. I was storing the documents in another application table.
    The after submit process grabs the id from wwv_flow_files where the name is = to your file input.
    After you add that ID and your associated master key in the collection, your final submit process fetches the files from wwv_flow_files and inserts them into your own table.
    I can put an example on apex.oracle.com if that would be helpful.
    Thanks,
    Jeff

  • How to upload multiple files into a server location at a single time

    Hi All,
    In my application i need to send multiple files from a particular page into the server location. In this page there will be an option to upload a file and after selecting the file , we will have an option asking if we were interested to send another file. It works just similar to google mail where we can multiple files at the same time. Right now though i had coded the uploading files concept i am facing some problems when trying to upload multiple files. All the files are being appended to a single file but i want them to be placed as different files at the specified location. Plz help me in this regard...
    Thanks in advance................,,

    Hi,
    i am sending the code in my prg. Have a look at it.
    var multi_selector = new MultiSelector( document.getElementById( 'files_list' ),3);
    In the above line i am specyfying that the maximum no. of files to be uploaded is 3. So if i upload less than 3 files, the program doesn't work and is not reading the uploaded files. If i upload 3 files it works fine. So please suggest me how to make this work irrespective of the no. of files uploaded using apache commons.
    My code is as follows:
    <form action="./servlet/Sample" method = "post" enctype="multipart/form-data">
         <!-- The file element -- NOTE: it has an ID -->
         <input id="my_file_element" type="file" name="file_1" >
         <input type="submit" name="submit1" value="submit">
    </form>
    Files:
    <!-- This is where the output will appear -->
    <div id="files_list"></div>
    <script>
         <!-- Create an instance of the multiSelector class, pass it the output target and the max number of files -->
         var multi_selector = new MultiSelector( document.getElementById( 'files_list' ),3);
         <!-- Pass in the file element -->
         multi_selector.addElement( document.getElementById( 'my_file_element' ) );
    </script>

Maybe you are looking for

  • How to connect my piano to my Macbook Pro?

    Hi and thanks so much for your help and time!! I need to connect my piano ( Yamaha Cp33 Stage Piano ) to my Macbook Pro 15'' to use it with GarageBand and Logic Studio. How may I do so (in detail)? Thanks again!

  • AdvancedDataGrid Columnspan in a single row?

    Is there a way to span two or more columns inside an AdvancedDataGrid only in one or more specific rows? Basically I need something like this: 1 | 2 | 3 | 4 | span 3 cols | 4 | 1 | 2 | 3 | 4 | 1 | span 2 cols | 4 Thanks.

  • Controlling Powermac G4 with powerbook G4 keyboard- oT?

    This may be off topic. My questions is this. I have a Powermac G4- dual 867. It has music DSP cards installed(UAD-1 etc). I travel frequently on short road trips and I want to be able to do some writing and mixing while on the road. Several of my pro

  • Application dock and multiple monitors

    I'm moving my MacBook around quite a bit and hence connect it to a few different monitors. My preferred setup is then to extend the desktop to cover both monitors, and have the external monitor configured in OSX as it is physically placed at the desk

  • Problem with  M-JPEG by using JMF and JPEGCodec .

    Hi, there, I want to implement a M-JPEG using JMF and JPEGCodec, is that possible?(I already been trapped) My problem is I have a video clip which is a AVI file, the video format is following: Video format: RGB, 160x120, FrameRate=14.9, Length=57600,