The moose likes JSP and the fly likes Why when click link does page say method=post yet request getParameter null? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Why when click link does page say method=post yet request getParameter null?" Watch "Why when click link does page say method=post yet request getParameter null?" New topic
Author

Why when click link does page say method=post yet request getParameter null?

Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
I have a link: edit.jsp?EditUser=True
when a person clicks that link, I have a check:
if ( request.getMethod().equalsIgnoreCase( "POST" ) )
{
...
}
It goes in there! (That is weird) But when I then call request.getParameter( "EditUser" ) it has nothing. Even further, when I get the eunmeration of parameter names, it's empty! Why is it considered a post yet there's nothing there? Is the only way to parse the query string?
Bhushan Jawle
Ranch Hand

Joined: Nov 22, 2001
Posts: 247
QueryString makes sense in GET method, POST method dosen't pass anything (as querystring) with URL
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
right....but, please read what I wrote. I clicked a link (with a querystring in it) YET the page prints out that the request method is POST! THAT is what makes no sense.
Bhushan Jawle
Ranch Hand

Joined: Nov 22, 2001
Posts: 247
I thought your question was "Why do I get null with getParameter()?"
From your answer it appears that "Why does POST gets called?" is the question.
I am guessing that if get into POST method, there has to be some javascript which is submiting the form on clicking the link. By default hyperlink should use GET.
David Hibbs
Ranch Hand

Joined: Dec 19, 2002
Posts: 374
As for why you're getting a post, this is dependent on your servlet engine. This is due to the fact that requests for the JSP go to the JSP engine, which in turn calls the service method, which may choose whether to call doGet() or doPost() or even set the method.
As for your null parameter issue...
Quoth the servlet API:
"For HTTP servlets, parameters are contained in the query string or posted form data. "
So if you posted it, it should still be present for calls to getParameter. The key is that parameter names are case sensitive, and I'm willing to bet that you didn't copy/paste your source code into your post, retyping it instead.
As for all the parameters, remember that getParameterNames returns an Enumeration which you must use properly in order to see the results.
If you post your exact code (the relevant sections at least), it would help us to help you.


"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
 
 
subject: Why when click link does page say method=post yet request getParameter null?
 
Threads others viewed
need help
Struts Validator and Dynamically Populated Select Lists
I can't find where to download struts...
Writing an Interface
is the War on Terror a War on Islam?
IntelliJ Java IDE