aspose file tools*
The moose likes Servlets and the fly likes text field returns null on servlet with file - text field combination Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "text field returns null on servlet with file - text field combination" Watch "text field returns null on servlet with file - text field combination" New topic
Author

text field returns null on servlet with file - text field combination

jill Na
Greenhorn

Joined: Dec 05, 2010
Posts: 11
Hi,

I created a simple jsp form where I am uploading a file and a text field to filled by the user -



Servlet does this -
String Caption = request.getParameter("CaptionVal");
always returns null

Would you know why? On removing file I think this would work, as it works on other jsp - servlet pages ... or any thing foolish that you see? am using commons file upload jar ...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

Servlet containers do not parse multi-part forms, so none of the parameter retrieval methods work.

You'll need to use the commons upload library API to parse the multi-part request and get the params. See the JSP FAQ for more info.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

You're using Commons File Upload -- which reads the whole request itself, including all the parameters. But there's a way to ask File Upload for a request parameter, although I don't remember what it is. But I do remember they have pretty good examples so maybe they have an example of that.
jill Na
Greenhorn

Joined: Dec 05, 2010
Posts: 11
Thanks Bear and Paul for prompt replies.
Actually that is my problem too, I tried to use common upload jar's method to retrieve the text box and its value

For instance the notes suggest -



name returns "CaptionVal" which is correct.
but for Value eclipse always complains that the method getString does not exist.
I tried the rest of the methods for the same but none of these returned the value I was looking for
String fieldName = item.getFieldName();
String fileName = item.getName();
String contentType = item.getContentType();
boolean isInMemory = item.isInMemory();
long sizeInBytes = item.getSize();


The jar I am using is

commons-fileupload-1.2.2
commons-io-2.0.1

http://commons.apache.org/fileupload/using.html
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

It's impossible to tell from your code fragment whether the "item" variable refers to a FileItem object. Based on the FileItem documentation and the Eclipse error message I would have to say it isn't.
jill Na
Greenhorn

Joined: Dec 05, 2010
Posts: 11
got it working using getFieldName

this is what I was / am still doing.
but item.getString() did not work.



Thanks for all the help and replies ....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: text field returns null on servlet with file - text field combination