Help coderanch get a
new server
by contributing to the fundraiser
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

FileUpload - Form Fields shows Null value

Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Below is my servlet code, where I can save the file locally at the given location. My problem is , I have a text box on JSP , where user enters company name in the text box. When I was trying to get the value of text box, it is throwing null.

I have searched on forums...and it says if ENCTYPE="multipart/form-data ..we cannot get the form field values..
Anyone can help on a way to get my form field.

FileItemFactory factory = new DiskFileItemFactory();
boolean isMultipart = FileUpload.isMultipartContent(request);
ServletFileUpload upload = new ServletFileUpload(factory);
List /* FileItem */ items = upload.parseRequest(request);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem);
String formFieldValue = request.getParameter("fileName"); /////It shows NULL value.
if (item.isFormField()) {
System.out.println("It is a field");
} else {
System.out.println("its a file");
String name = item.getFieldName();
String value = item.getString();
File cfile=new File(item.getName());

File folder;

folder = new File("C:/upload/documents");
folder = new File("C:/upload/images");
File tosave=new File(folder,cfile.getName());


<TR border="0">
<TD >File Location <input type="file" name="uploadFile" id="uploadFile" ></TD>
<TR border="0">
<TD>File Name <input type="text" name="fileName" > <input type="SUBMIT" value="Upload" ></TD>

Posts: 67750
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please see the Servlets FAQ entry on file uploading.
[ October 19, 2007: Message edited by: Bear Bibeault ]
What a stench! Central nervous system shutting down. Save yourself tiny ad!
We need your help - Coderanch server fundraiser
    Bookmark Topic Watch Topic
  • New Topic