This week's book giveaway is in the Java in General forum.
We're giving away four copies of Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework and have Michael Redlich on-line!
See this thread for details.
  • 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

help: getParameter returning null!

 
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 67752
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
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
Sheriff
Posts: 67752
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
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
 
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67752
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

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
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanx,guys!
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic