• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
jill Na
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Pie
Posts: 20729
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20729
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic