Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help: getParameter returning null!

 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought I was getting the hang of JSP syntax, but I just don't know what's wrong here. I have a select drop-down thingie in my HTML that looks like this:

I have the form going back to the same page, and at the top I have the following JSP code:

It keeps printing out "method is null", and I don't know why! Obviously, I want it to say something like "method is ImportAddressesAuto", but I don't understand why the parameter is not getting set, or being reset to null.
Thanks for your help!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65337
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried your code by embedding it in the following HTML file, and it worked perfectly as expected (Tomcat 4.1.27).

If this example doesn't work for you, something else is afoot.
bear
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65337
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, in the following line:

the cast to String is not necessary; getParameter() always returns a String. This won't cause any problems, but the superfluous cast should be removed for clarity.
bear
 
Tim Baker
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by S. C. Huey:


It keeps printing out "method is null", and I don't know why!

at no place will it print out method is null. when the parameter is null it does nothing and when it is something it prints out "methid is NOT null"
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ugh! I was making a new page by copying an old one and modifying it, and that old one was for uploading a file, and I even though I had changed the form action, I hadn't paid attention to the rest of the form tag, and was telling it the enctype was MULTIPART/FORM-DATA!


Changing it to this causes it to work just fine:



:roll:
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65337
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
at no place will it print out method is null.

Actually it will. The print statement is outside the if block (but the formatting of the code sorta hides that fact).
bear
 
dragon ji
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,all
I can't get parameter in url if set enctype='MULTIPART/FORM-DATA' in <form>,
why?
How can I get it?
 
Sona Bhavani
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by dragon ji:
Hi,all
I can't get parameter in url if set enctype='MULTIPART/FORM-DATA' in <form>,
why?
How can I get it?

You will not get the parameters with usual request.getParameter method if the enctype is set to 'MULTIPART/FORM-DATA' . Are you uising this to upload a file.
Wherever you are trying to retrieive this parameter first create a MultipartRequest object and then do it
For Example:
MultipartRequest mutlipartrequest = new MultipartRequest(request,path,5*1024);
String name = multipartrequest.getParameter("name");
Hope this helps.
Sona.
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's that MultiPartRequest class you're talking about? Is it the one in the com.oreilly.servlet.MultipartRequest package? Do you see a lot of advantage in using that over the standard FileUploadBean code that's out there, or do you basically just get the same functionality?
These aren't exactly what I used, but in case you don't know what I'm talking about (and also for the sake of anyone searching this forum), here are some examples:
http://www.akadia.com/download/soug/tomcat/html/file_upload_bean_java.html
http://www.onjava.com/pub/a/onjava/2001/04/05/upload.html
 
dragon ji
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx,guys!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic