Posting a form without changing pages in jsp
In jsp, how do you submit a form without changing the page?
In essence I am trying:
1) First start the servlet on the backend with a message to handle the HttpServletRequest. 2) Second, once the servlet finishes, the response message will be sent to a DIV on the page using the Ajax.Updater prototype.
All without leaving the page, of course.
You can do it via jQuery.AJAX: http://docs.jquery.com/Ajax
example : $.post(servleturl, paramters, callbackfunction, "html");
a source to share
There are two methods that I am aware of. First, you can extract values from the form and expose them as a separate Ajax.Request. Alamar has posted some good instructions on this:
Use Form.serialize (true) to get a hash of parameter names as keys.
You can do whatever you want. a hash that includes removing inputs, changing their values, filtering them, etc.
Ajax.Updated will then take this modified hash as a parameter.
Another method is to create an iFrame that will accept the response from your form request using the target property on the form element. If you are running on the same domain, you will be able to access the content of that iFrame and can use the returned information there to update the parent page with any posts you want to return. This approach is more confusing, but necessary in some cases. For example, if you are working with file upload inputs, the serialized hash in the first approach will not work.
a source to share