• Post Reply 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ...
 
Sheriff
Posts: 67746
173
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:
  • 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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ....
reply
    Bookmark Topic Watch Topic
  • New Topic