Bonjour,

Voici le ActionForm tout simple qui sert à stocker un fichier uploadé :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package pages.engin.importer;

import org.apache.struts.action.ActionForm;
import org.apache.struts.upload.FormFile;

public class ImporterForm extends ActionForm
{
    private static final long serialVersionUID = 1L;
    
    // objet contenant le fichier uploadé
    private FormFile fichier;

    public FormFile getFichier()
    {
        return fichier;
    }

    public void setFichier(FormFile fichier)
    {
        this.fichier = fichier;
    }

    
    
}
... voici le JSP correspondant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<%@ page language="java"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/struts-html-el" prefix="html-el"%>
<%@ taglib uri="/tags/struts-bean-el" prefix="bean-el"%>
<%@ taglib uri="/tags/struts-nested" prefix="nested"%>

<%@ taglib uri="/tags/jstl-c" prefix="c"%>
<html-el:xhtml />

<%@ page import="global.Global"%>

<h1><bean-el:message key="Importer-engins" /></h1>

<p class="messageImportant"><html-el:errors
    property="ATT_ERREUR_GLOBAL" /></p>

<html-el:form action="/enginAfficherImporter.do">

    <p class="texteCentre"><strong> <bean-el:message
        key="Indiquer-nom-sauvegarde" />&nbsp;:&nbsp;</strong> 
    <br />
    <br />
    </p>

        <table class="positionnerCentre">
            <tr>
            <td colspan="3"><span class="messageImportant"> <html-el:errors
                property="ATT_ERREUR" /> </span></td>
        </tr>

        <tr>    
            <td>
            <html-el:file property="fichier"/>
            </td>
        </tr>
            
        <tr>
            <td>
            <br />
            <input type="image" 
                src="<%=Global.WEB_REP_STYLE_IMAGES + Global.WEB_SEPARATOR%>checkin.png" 
                class="bouton positionnerDroite"
                alt="<bean:message key='Valider'/>"
                title="<bean:message key='Valider'/>" />
            </td>
        </tr>    
        
        </table>

</html-el:form>
... voici la définition dans le fichier de configuration :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
        <action
            path="/enginAfficherImporterSelectionner"
            type="pages.engin.importer.AfficherSelectionnerAction"
            name="EnginImporterForm"
            scope="request"
            validate="false">
            <forward name="enginImporterSelectionner" path="engin-importer-selectionner"/>
            <forward name="erreur" path="erreur-administrateur"/>
        </action>

... avec ...

<form-bean name="EnginImporterForm" type="pages.engin.importer.ImporterForm"/>
... et la belle exception lors de la validation du formulaire :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
Method invocation failed.
java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...

"Servlet.service()" pour la servlet action a généré une exception
java.lang.IllegalArgumentException: Cannot invoke pages.engin.importer.ImporterForm.setFichier - argument type mismatch
    at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:1778)
...
Pourtant j'ai déjà fait ce genre de fonction et dans une autre partie de mon programme cela fonctionne.

Alors pourquoi cette erreur ?

Merci.