Bonjour,

j'ai un formulaire dans lequel je fais l'upload d'un fichier ...

sans multipart/form-data mes champs renseignés prennent bien une valeur mais pas d'upload

avec multipart/form-data mes champs retournent null et pas d'upload non plus

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
 
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.commons.fileupload.*;
 
@SuppressWarnings("serial")
public class creerDoc extends connect {
 
    /**
     * Client XMLRPC
     */
    private XMLClient clientXML = null;
 
    /**
     * Chemin pour déposer le fichier audio
     */
    private String chemin = "/home/netjukebox/";
 
    /**
     * Requête de création d'un document
     */
    @SuppressWarnings({"deprecation","deprecation"})
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 
        HttpSession session = request.getSession();
        clientXML = (XMLClient) session.getAttribute("client");
 
        String titre = request.getParameter("titre");
        String duree = request.getParameter("duree");
        String jour = request.getParameter("jour");
        String mois = request.getParameter("mois");
        String annee = request.getParameter("annee");
        String source = request.getParameter("source");
        String langue = request.getParameter("langue");
        String genre = request.getParameter("genre");
        String fichier = chemin + titre;
        String artiste = request.getParameter("artiste");
        String interprete = request.getParameter("interprete");
        String compositeur = request.getParameter("interprete");
 
        System.out.println(titre);
        System.out.println(duree);
        System.out.println(jour);
        System.out.println(mois);
        System.out.println(annee);
        System.out.println(source);
        System.out.println(langue);
        System.out.println(genre);
        System.out.println(fichier);
        System.out.println(artiste);
        System.out.println(interprete);
        System.out.println(compositeur);
 
        response.setContentType("text/html");
 
        boolean cree = clientXML.creerDocument(titre, duree, jour, mois, annee, source, langue, genre, fichier,  artiste, interprete, compositeur);
 
        if (cree) {
            try{        
                // Create a new file upload handler 
                DiskFileUpload upload = new DiskFileUpload(); 
 
                // Set upload parameters 
                int  yourMaxMemorySize = 512 * 1024 * 8;
                int  yourMaxRequestSize = 1024 * 1024 * 8; 
 
                upload.setSizeThreshold(yourMaxMemorySize); 
                upload.setSizeMax(yourMaxRequestSize); 
                upload.setRepositoryPath(chemin); 
 
                //Parse the request
                List items = upload.parseRequest(request);
 
                // Process the uploaded items 
                Iterator iter = items.iterator(); 
                while (iter.hasNext()) { 
 
                    FileItem item = (FileItem) iter.next(); 
 
                    //   Process a regular form field 
                    if (item.isFormField()) { 
                        @SuppressWarnings("unused") String name = item.getFieldName(); 
                        @SuppressWarnings("unused") String value = item.getString(); 
                    } 
                    // Process a file upload 
                    else { 
                        @SuppressWarnings("unused") String fieldName = item.getFieldName();
                        String fileName = item.getName();
                        @SuppressWarnings("unused") String contentType = item.getContentType();
                        @SuppressWarnings("unused") boolean isInMemory = item.isInMemory();
                        File uploadedFile = new File(chemin + fileName);
                        item.write(uploadedFile);
                    } 
                } 
            } catch (ServletException e) { 
                e.printStackTrace(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } catch (FileUploadException e) { 
                e.printStackTrace(); 
            } catch (Exception e) { 
                e.printStackTrace(); 
            }
 
            response.sendRedirect("http://localhost/creation.html");
        } else {
            response.sendRedirect("http://localhost/erreur.html");
        }
    }
}
merci d'avance pour toute aide

Dom