Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
QueryString makes sense in GET method, POST method dosen't pass anything (as querystring) with URL
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!