Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

getParameter returns null

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no idea why I am getting null parameters from form in my app. I've spend at least couple hours trying to figure it out.

Servlet:


JSP:
 
Sheriff
Posts: 67266
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please provide more info. For example, which call is failing? What did you expect? What are you getting?

Thanks for using code tags for your code; good work!
 
Michal Kwasniewski
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to get parameters from jsp and write it to my pseudo database (private List<Ad> aDatabase = new ArrayList<>();)
The problem is : when I fill my form and click submit button it returns null values to my servlet ( that's why I've used println to check if I am getting null values for every parameter).
Probably I am doing something wrong, I would be very grateful for any hints.
 
Bear Bibeault
Sheriff
Posts: 67266
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup, why is your form declared to submit multi-part form data?
 
Michal Kwasniewski
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have changed it to text/plain, but it doesn't make a difference
 
Bear Bibeault
Sheriff
Posts: 67266
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying random things is never going to work well. "text/plain" makes no sense at all.

If you want to use the default encoding type (which you do), just leave the enctype attribute off.
 
Bear Bibeault
Sheriff
Posts: 67266
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You only want to use a multi-part form when uploading files, and then the getParameter() family of methods will not work. You must process a multi-part submission differently than a "normal" submission.

By the way, the default encoding is "application/x-www-form-urlencoded". But it's best just to let it default.
 
Michal Kwasniewski
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks, now it's working
 
Bear Bibeault
Sheriff
Posts: 67266
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why did you specify a multi-part form in the first place?
 
Michal Kwasniewski
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because I have based my app on some example app in which you can upload file. I didn't think that this encoding will make such a difference.
 
Bear Bibeault
Sheriff
Posts: 67266
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Michal Kwasniewski wrote:Because I have based my app on some example app in which you can upload file. I didn't think that this encoding will make such a difference.



Yes, it will. As you've seen, and as I pointed out, using the wring encoding makes a big difference.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!