the fileupload examples should be included in struts2-showcase webapp

WEB-INF/classes/struts.xml contains the inclusion of struts-fileupload.xml as 
illustrated here
<include file="struts-fileupload.xml" />

<!-- Where the struts-fileupload.xml contents contain -->
<?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>
    <package name="fileupload" extends="struts-default" namespace="/fileupload">
        
        <action name="upload" 
class="org.apache.struts2.showcase.fileupload.FileUploadAction" method="input">
            <result>upload.jsp</result>
        </action>

        <action name="doUpload" 
class="org.apache.struts2.showcase.fileupload.FileUploadAction" method="upload">
            <result name="input">upload.jsp</result>
            <result>upload-success.jsp</result>
        </action>
        
        <action name="multipleUploadUsingList">
            <result>multipleUploadUsingList.jsp</result>
        </action>
        
        <action name="doMultipleUploadUsingList" 
class="org.apache.struts2.showcase.fileupload.MultipleFileUploadUsingListAction"
 method="upload">
            <result>multipleUploadUsingList-success.jsp</result>
        </action>


        <action name="multipleUploadUsingArray">
            <result>multipleUploadUsingArray.jsp</result>
        </action>

        <action name="doMultipleUploadUsingArray" 
class="org.apache.struts2.showcase.fileupload.MultipleFileUploadUsingArrayAction"
 method="upload">
            <result>multipleUploadUsingArray-success.jsp</result>
        </action>


    </package>
</struts>

//$STRUTS2_HOME/apps/struts2-showcase-2.1.2/fileupload/upload-success.jsp
<%@ page 
    language="java" 
    contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
    <title>Showcase</title>
</head>
<body>
<h1>Fileupload sample</h1>
<p>
    <ul>
        <li>ContentType: <s:property value="uploadContentType" /></li>
        <li>FileName: <s:property value="uploadFileName" /></li>
        <li>File: <s:property value="upload" /></li>
        <li>Caption:<s:property value="caption" /></li>
    </ul>
</p>
</body>
</html>

//$STRUTS2_HOME/apps/struts2-showcase-2.1.2/fileupload/multipleUploadUsingList.jsp
<%@ page 
    language="java" 
    contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Showcase - fileupload - multiple fileupload using List</title>
</head>
<body>

<s:form action="doMultipleUploadUsingList" method="POST" 
enctype="multipart/form-data">
    <s:file label="File (1)" name="upload" />
    <s:file label="File (2)" name="upload" />
    <s:file label="File (3)" name="upload" />
    <s:submit />
</s:form>
</body>
</html>

<!-- notice the change in name to upload -->
//
/* $Id: MultipleFileUploadUsingListAction.java 478625 2006-11-23 17:31:52Z 
wsmoak $
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.struts2.showcase.fileupload;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
/**
 * Showcase action - multiple file upload using List
 * @version $Date: 2006-11-23 11:31:52 -0600 (Thu, 23 Nov 2006) $ $Id: 
MultipleFileUploadUsingListAction.java 478625 2006-11-23 17:31:52Z wsmoak $
 */
public class MultipleFileUploadUsingListAction extends ActionSupport {

    private List<File> uploads = new ArrayList<File>();
    private List<String> uploadFileNames = new ArrayList<String>();
    private List<String> uploadContentTypes = new ArrayList<String>();

    public List<File> getUpload() {
        return this.uploads;
    }
    public void setUpload(List<File> uploads) {
        this.uploads = uploads;
    }

    public List<String> getUploadFileName() {
        return this.uploadFileNames;
    }
    public void setUploadFileName(List<String> uploadFileNames) {
        this.uploadFileNames = uploadFileNames;
    }

    public List<String> getUploadContentType() {
        return this.uploadContentTypes;
    }
    public void setUploadContentType(List<String> contentTypes) {
        this.uploadContentTypes = contentTypes;
    }

    public String upload() throws Exception {

        System.out.println("\n\n upload1");
        System.out.println("files:");
        for (File u: uploads) {
//place the identifying mechanism for the filename here e.g. u.getName();
            System.out.println("*** "+u+"\t"+u.length());
        }
        System.out.println("filenames:");
        for (String n: uploadFileNames) {
//n must equal the u.getName from above
            System.out.println("*** "+n);
        }
        System.out.println("content types:");
        for (String c: uploadContentTypes) {
            System.out.println("*** "+c);
        }
        System.out.println("\n\n");
        return SUCCESS;
    }
}

//if you want a more overt mechanism to identify which file you will be 
processing you can use the status.index illustrated
<%...@taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Insert title here</title>
</head>
<body>

<!-- uniqueness of the uploaded file is guaranteed by the Struts iterator tag 
#stat.index -->
<table border="1">
<s:iterator value="upload" status="stat">
<tr>
    <td>File <s:property value="%{#stat.index}" /></td>
    <td><s:property value="%{upload[#stat.index]}" /></td>
</tr>
</s:iterator>
</table>

<table border="1">
<s:iterator value="uploadFileName" status="stat">
<tr>
    <td>File Name <s:property value="%{#stat.index}" /></td>
    <td><s:property value="%{uploadFileName[#stat.index]}" /></td>
</tr>    
</s:iterator>
</table>

<table border="1">
<s:iterator value="uploadContentType" status="stat">
<tr>
    <td>Content Type <s:property value="%{#stat.index}" /></td>
    <td><s:property value="%{uploadContentType[#stat.index]}" /></td>
</tr>
</s:iterator>
</table>
</body>
</html>

HTH
Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger 
sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung 
oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem 
Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. 
Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung 
fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le 
destinataire prévu, nous te demandons avec bonté que pour satisfaire informez 
l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est 
interdite. Ce message sert à l'information seulement et n'aura pas n'importe 
quel effet légalement obligatoire. Étant donné que les email peuvent facilement 
être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité 
pour le contenu fourni.




> Date: Sun, 14 Jun 2009 09:00:05 -0700
> From: lampa2...@gmail.com
> To: user@struts.apache.org
> Subject: multiple FileUpload Problem
> 
> 
> Hi All:
>   I can post the File to my action and store them in database using  tag:
> <s:file name="upload" />.
>   According to Struts 2 , the "name" must be assigned as "upload". However,
> why not the "name" are assigned to different value? just like it :
>   <s:file name="upload1" />
>   <s:file name="upload2" />
>   <s:file name="upload3"/>
> 
>   If so, we can very clear that  which input tag submit the upload file in
> the JSP. Because after upload file is submitted, the upload file will be put
> into a list, you cannot find which tag submit the upload file.
> 
>   I just think there is something inconvenient. 
>   Who can give me some advices ?
> 
> Lampa
>  
> -- 
> View this message in context: 
> http://www.nabble.com/multiple-FileUpload-Problem-tp24023039p24023039.html
> Sent from the Struts - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
> 

_________________________________________________________________
Hotmail® has ever-growing storage! Don’t worry about storage limits. 
http://windowslive.com/Tutorial/Hotmail/Storage?ocid=TXT_TAGLM_WL_HM_Tutorial_Storage_062009

Reply via email to