| Author |
help: getParameter returning null!
|
Stephen Huey
Ranch Hand
Joined: Jul 15, 2003
Posts: 618
|
|
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
Joined: Jan 10, 2002
Posts: 56163
|
|
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
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56163
|
|
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
Joined: Oct 04, 2003
Posts: 541
|
|
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"
|
Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
|
 |
Stephen Huey
Ranch Hand
Joined: Jul 15, 2003
Posts: 618
|
|
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
Joined: Jan 10, 2002
Posts: 56163
|
|
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
Joined: Oct 31, 2002
Posts: 110
|
|
Hi,all I can't get parameter in url if set enctype='MULTIPART/FORM-DATA' in <form>, why? How can I get it?
|
scjp 1.4<br />challenge haven't limit!
|
 |
Sona Bhavani
Greenhorn
Joined: Nov 12, 2003
Posts: 6
|
|
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
Joined: Jul 15, 2003
Posts: 618
|
|
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
Joined: Oct 31, 2002
Posts: 110
|
|
|
thanx,guys!
|
 |
 |
|
|
subject: help: getParameter returning null!
|
|
|