Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

getParameter returns null  RSS feed

 
Michal Kwasniewski
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:
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!