After looking through the forums, I've yet to discover a post which illustrates my problem. I keep getting null values when using request.getParameter() to get fields from a form passed to a JSP page using POST. I've created a form which will feed into a JDBC function on the target page. The page this originates from uses one Ajax function, which is invoked from other functions that are linked to a pair of dropdowns (using GET) and a submit button (using POST). As such, I've written my ajax function to check the form method, and default to configuration for GET. Thus, if both dropdowns are set to a value other than the default, the GET method populates a SPAN with a multiple-enabled dropdown. Once you finish the form and click on the submit button, it calls a POST method :
form action='#' name='XXXX' onSubmit="post_process();return false;"
The post_process() function sets the target URL, passes a reference to the Ajax function for the correct span, and attempts to get a response. I can get the page to pass back HTML detailing that all values are set to null on the target page, which gets written to the <SPAN> which is passed into the Ajax function by post_process(). The end result is that the user never leaves the page, because the second div is populated by being passed to post_process() so I can display error messages to the user. As an example, if I pass an invalid employee ID to the target page, it will concatenate to the error output collector "Invalid employee id." and a break tag, which will get printed to the page with an out.println at the end. The original plan I had was to use this to get a more verbose error message to the user.
Here's the issue I'm experiencing:
If I leave the enctype characteristic alone, I get all nulls when using request.getParameter() in the target page. I also tried request.getAttribute. If I use the XMLHttpRequest object method setRequestHeader() and pass it ("Content-Type", "appliction/x-www-form-urlencoded;") without passing the send() method anything, the whole page reloads itself despite my having specified that it should not do so whether I set action="" or action="#". I've checked the URL passed in Firebug with both of these set-ups, and the form is appending the arguments to the end of its own url. I then tried feeding the rep ID by setting a string to "repid=1" and passing that to xmlhttprequest.send(). This had the same effect. Is there a way to get this code to stop passing nulls?
Is anyone else seeing that as just a big block of text? I don't even see line breaks or formatting.
Bear: Yes, in the description of the issue, I mention that Firebug is showing a request to a page, but the document containing the form is calling itself with the values chained after. I had it invoking the proper CGI form before, and in the process of trying to fix the null values I've now got it calling itself instead.
Sorry, was trying to edit the code. It turns out, if the code opening tag in on the same line as the first bit of code, it gets thrown off. Is that what you meant by re-posting? If not, I'm afraid I'm not understanding your question. If you mean why did I post the code, it's because you asked that I specifically post the Ajax code. Since it's short, and circuitous, I thought posting the whole ajax function would keep me from obfuscating the issue, as I might if I only posted what I thought was necessary.
Edited to add: I should really clarify this point: loadStep() is called by the dropdowns. It tests that both of them have been set to a non-zero value before sending a request to the server for the multiple-enabled dropdown which loadQuestions.jsp feeds back. After the form is filled out, clicking on the submit button invokes post_failure().
OK, after working on this more, I've found something:
Removing lines 29 and 30 cause the page to stop reloading itself, and instead call the proper target page. However, this means (if I understand correctly) that I'm now using the default encoding for GET methods, which I thought was going to cause problems with POST. Oddly enough, leaving the string "args" being passed to send() didn't change anything or cause errors to show up in firebug. Further, Firebug shows that I have posted one value from the form, which makes sense since I specifically fetch it on line 31. However, the target page still doesn't seem to be picking up on that. I added the argument "foo=bar" and according to Firebug, that got sent in the POST as well.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop