Results 1 to 1 of 1
Thread: JSP/Ajax/Post giving null values
- 04-22-2010, 10:02 PM #1Member
- Join Date
- Apr 2010
- Meriden, CT
- Rep Power
JSP/Ajax/Post giving null values
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?
- By fneeks in forum New To JavaReplies: 1Last Post: 04-07-2010, 08:48 PM
- By jabo in forum New To JavaReplies: 3Last Post: 03-31-2010, 03:44 PM
- By Sachin. in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 09-27-2009, 02:24 AM
- By jeremy.wilson in forum New To JavaReplies: 1Last Post: 08-05-2009, 02:43 AM
- By Ms.Ranjan in forum New To JavaReplies: 4Last Post: 05-21-2009, 10:29 PM