Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

Problems using jakarta commons fileUpload

Thread view: 
Pablo - 20 Nov 2006 22:00 GMT
Hi all,

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???

Regards,
Pablo
Manish Pandit - 21 Nov 2006 00:43 GMT
Hi,

You will have to use the API provided by DiskUpload, and do a
parseRequest() and get the parameters. Given the fact that the request
is multipart, you cannot have access to the parameters via
getParameter().

You can search for this on google or even this group - I remember
answering a similar question with a code sample some time in September.

-cheers,
Manish
Arne Vajhøj - 21 Nov 2006 01:13 GMT
> 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
[quoted text clipped - 22 lines]
>
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.