Question: Uploading Multiple Image On Server?

Ads

 
 
 

Share on Google+Share on Google+

bhushanjaware
Uploading Multiple Image On Server?
2 Answer(s)      5 years and a month ago
Posted in : Struts

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.

Ads
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>

Ads









Tutorials   
Java Spring Hibernate Struts Training Dynamic tabs in struts 1.2 Unable to upload a file to mysql database using struts1 Pagination in struts 2 struts2 filterdispatcher is deprecated please use the new filters viewing How to add struts2 dependency in Maven? Struts Exception Handling can you check below code if any erors multimedia how to display the value of termcell name in label class not found exception Where to learn Struts 2? dropdown cacheing Upload and Download Large files in jsp What is Struts 2 framework struts and hibernate based health care project source code struts and hibernate based health care project source code Struts 2 Integration with Struts 1 About captcha of strut2 About captcha of strut2 Which is the good website for struts 2 tutorials? advance java source code source code In Struts 2 how to pass the Struts struts internationalization for Korean language struts2 Struts2 and Hibernate Fetch Data Base Value Struts2 and Hibernate Fetch Data Base Value Struts2 and Hibernate i want to create an application with only a button which on click displays table from database using struts2 and hibernate on eclipse Struts2 and Hibernate Struts2 and Hibernate Struts2 validation Procedure Struts2 validation Procedure Struts2 validation Procedure Struts2 validation Procedure Struts 2 action-validation.xml not loading Struts-2 and Ajax integration STRUTS QUESTION conerting web project into .exe file About Select tag ScartApplication aplicacion ecommerce struts 1.3 struts 1.3 sms prob Need to know struts1 all jar file names struts with hibernate

Ads

 
Advertisement null

Ads