Comment faire un upload de fichier vers le serveur à partir d'une machine client par JSP
Version imprimable
Comment faire un upload de fichier vers le serveur à partir d'une machine client par JSP
Code:
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 public void readBLOB( String fichier) throws IOException, SQLException { FileOutputStream outputFileOutputStream = null; InputStream blobInputStream = null; String sqlText = null; Statement stmt = null; ResultSet rset = null; BLOB image = null; int chunkSize; byte[] binaryBuffer; int bytesRead = 0; int bytesWritten = 0; int totBytesRead = 0; int totBytesWritten = 0; try { stmt = conn.createStatement(); outputBinaryFile2 = new File(fichier); outputFileOutputStream = new FileOutputStream(outputBinaryFile2); sqlText = "SELECT image " + "FROM test_blob " + "WHERE id = 183 " + "FOR UPDATE"; rset = stmt.executeQuery(sqlText); rset.next(); image = ((OracleResultSet) rset).getBLOB("image"); blobInputStream = image.getBinaryStream(); chunkSize = image.getChunkSize(); binaryBuffer = new byte[chunkSize]; while ((bytesRead = blobInputStream.read(binaryBuffer)) != -1) { outputFileOutputStream.write(binaryBuffer, 0, bytesRead); totBytesRead += bytesRead; totBytesWritten += bytesRead; } outputFileOutputStream.close(); blobInputStream.close(); conn.commit(); rset.close(); stmt.close(); System.out.println( "==========================================================\n" + " INPUT STREAMS METHOD\n" + "==========================================================\n" + "Wrote BLOB column data to file " + outputBinaryFile2.getName() + ".\n" + totBytesRead + " bytes read.\n" + totBytesWritten + " bytes written.\n" ); } catch (IOException e) { System.out.println("Caught I/O Exception: (Write BLOB value to file - Streams Method)."); e.printStackTrace(); throw e; } catch (SQLException e) { System.out.println("Caught SQL Exception: (Write BLOB value to file - Streams Method)."); System.out.println("SQL:\n" + sqlText); e.printStackTrace(); throw e; } }
Bonjour,
j'ai un probleme lors de la recupération de mes input en mode enctype="multipart/form-data"
Comme vous l'aurez compris, je souhaite realiser un upload.
or lorsque je rentre "héhé" dans un de mes input, je récupère "hAchAc" (avec le c de copyright)
Ma librairie d'upload est : FileUpload si c'est la cause de mon probleme.
Merci pour vos suggestions.
tu as bien ça comme ça dans la form de ta jsp ?
Code:<FORM enctype="multipart/form-data" method="POST"