Uploading Multiple Image On Server?

Uploading Multiple Image On Server?

Hello sir, I am stuck with a problem of uploading multiple images on server. i have done a code which works fine for uploading single image,but it doesn't work with uploading multiple images dynamically on server. one live example of this is like facebook uploading images. so please help me to solve this problem.

View Answers

April 5, 2012 at 5:53 PM

1)MultipleFileUpload.java

import java.io.File;
    import java.util.ArrayList;
    import java.util.List;

    import com.opensymphony.xwork2.ActionSupport;

    public class MultipleFileUpload extends ActionSupport{

        private List<File> fileUpload = new ArrayList<File>();
        private List<String> fileUploadContentType = new ArrayList<String>();
        private List<String> fileUploadFileName = new ArrayList<String>();

        public List<File> getFileUpload() {
            return fileUpload;
        }

        public void setFileUpload(List<File> fileUpload) {
            this.fileUpload = fileUpload;
        }

        public List<String> getFileUploadContentType() {
            return fileUploadContentType;
        }

        public void setFileUploadContentType(List<String> fileUploadContentType) {
            this.fileUploadContentType = fileUploadContentType;
        }

        public List<String> getFileUploadFileName() {
            return fileUploadFileName;
        }

        public void setFileUploadFileName(List<String> fileUploadFileName) {
            this.fileUploadFileName = fileUploadFileName;
        }

        public String upload() throws Exception{

            for (File file: fileUpload) {
                System.out.println("File :" + file);
            }

            for (String fileName: fileUploadFileName) {
                System.out.println("Filename : " + fileName);
            }

            for (String fileContentType: fileUploadContentType) {
                System.out.println("File type : " + fileContentType);
            }

            return SUCCESS;

        }

        public String display() {
            return NONE;
        }

    }

2)fileupload.jsp:

<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<s:head />
</head>

<body>
<h1>Struts 2 upload multiple files example</h1>

<s:form action="resultAction" namespace="/" 
method="POST" enctype="multipart/form-data">

<s:file label="File 1" name="fileupload" size="40" />
<s:file label="File 2" name="fileupload" size="40" />
<s:file label="FIle 2" name="fileupload" size="40" />

<s:submit value="submit" name="submit" />

</s:form>

</body>
</html>

April 5, 2012 at 5:53 PM

3)result.jsp:

<%@ taglib prefix="s" uri="/struts-tags" %>
<html>

<body>
<h1>Struts 2 upload multiple files example</h1>

<h4>
   File Name : <s:property value="fileUploadFileName"/> 
</h4> 

<h4>
   Content Type : <s:property value="fileUploadContentType"/> 
</h4> 

<h4>
   File : <s:property value="fileupload"/> 
</h4> 

</body>
</html>

4)struts.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

    <constant name="struts.devMode" value="true" />

    <package name="default" namespace="/" extends="struts-default">

    <action name="multipleFileUpload" 
        class="../MultipleFileUpload" 
            method="display">
        <result name="none">pages/fileupload.jsp</result>
    </action>

    <action name="resultAction" 
         class="../MultipleFileUpload" 
             method="upload">
         <result name="success">pages/result.jsp</result>
    </action>
   </package>

</struts>









Related Tutorials/Questions & Answers:
Uploading Multiple Image On Server?
Image uploading
Advertisements
uploading image in php - PHP
Image uploading in FTP Server
change the name of the image after uploading the image
uploading image in the form
Uploading an image - JSP-Servlet
Uploading image using jsp
Uploading Multiple Files Using Jsp
Multiple file Uploading - JSP-Servlet
Uploading the multiple files
struts image uploading
struts image uploading
struts image uploading
struts image uploading
Uploading an image into the table - JSP-Servlet
ModuleNotFoundError: No module named 'serverD'
Uploading multiple files in JSP - JSP-Servlet
Problem in uploading image to to mysql database
Problem in uploading image to to mysql database
save the uploading image with user specified name
save the uploading image with user specified name
Uploading a Profile with image[file] into a sql database
uploading of image showing exception when size increases.
image uploading perminssion in server - JSP-Servlet
image uploading perminssion in server - JSP-Servlet
image uploading perminssion in server - JSP-Servlet
image uploading perminssion in server - JSP-Servlet
Need help in image uploading - JSP-Servlet
Multiple image upload using JSP
Storing Multiple image in sql using java
Socket and Servert -Jsp
display multiple image file or pdf file in multiple column of a row from server or database
error in uploading image from jsp to oracle 10g database
Uploading Employee Profile with image
Using a image for Browse button instead of normal html Browse button for Uploading files from a JSP - JSP-Servlet
Uploading Employee Profile with image
Bundle of servers
Uploading Multiple Files Using Jsp
web servers
Dedicated Servers
rename before uploading
Dedicated servers hosting
Uploading files
photo uploading
Servers and Operating Systems
Uploading website
uploading a file
uploading problem
uploading audio file iphone

Ads