How to Pass Parameters From JSP to JQuery
The JSP language helps programmers create dynamic Web pages. You use the "OnClick" event on your JSP forms to trigger an event that passes parameters to a jQuery function. jQuery is a form of Ajax that lets you process form requests without refreshing the entire page. The parameters you pass are used in the processing page to calculate and return responses to the reader.
Instructions
-
-
1
Right-click the JSP page you want to use to pass parameters. Click "Open With" and select your JSP editor.
-
2
Create the jQuery function that you use to parse the parameters. For instance, the following code displays a message box with the parameter value:
$(function() {
$('.alert-message').click( function() {
$.get( $(this).attr('param'), function(name) {
alert( "Hello: " + name);
});
});
}); -
-
3
Add the JSP code that calls the JSP function and passes the parameter using the "param " property in the tag. The following code calls the function when a user clicks the button:
<input type="button" param="Jim" class="alert-message" value="Click Here">
-
1