This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes FileUpload - Form Fields shows Null value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

FileUpload - Form Fields shows Null value

Rohit Kumar
Ranch Hand

Joined: Jul 19, 2007
Posts: 35
Hi,

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) iter.next();
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");
System.out.println(item.getName());
String name = item.getFieldName();
String value = item.getString();
File cfile=new File(item.getName());

File folder;

if(saveFile.endsWith("pdf")){
folder = new File("C:/upload/documents");
}
else{
folder = new File("C:/upload/images");
}
File tosave=new File(folder,cfile.getName());

MyJSP:

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

</TR>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

Please see the Servlets FAQ entry on file uploading.
[ October 19, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FileUpload - Form Fields shows Null value
 
Similar Threads
Getting 404 when i forward request using request dispetcher
Problem with file upload. Problem lies in javascript/dojo
how to upload using html or javascript?
Issues with uploading files and simple plain fields
Unable to get connection