palAlaa
palAlaa

Reputation: 9858

send parameter from request through json

How can I resend parameter I received from servlet to servlet using json.

Here's what I mean, I am using this way to pass parameters to servlet

<a href="StudentManagementServlet?page=${page}&isActivated=${isActivated}" >

but now, I wanna make it using json, so How can I reach ${page} and ${isActivated} from json?

Upvotes: 1

Views: 2191

Answers (1)

Tom Chandler
Tom Chandler

Reputation: 642

JSP parses the page before it sends it to the client, so you can use the ${variables} anywhere in the code, including inline in javascript.

To store them as a JavaScript object:

var obj = { page: ${page}, isActivated: ${isActivated} };

To store them as a JSON Object:

var jsonObject = { "page" : "${page}", "isActivated": "${isActivated}" };

Now, if you want to send it to a different servlet, you'll need to attach the JSON objectto a POST request to that servlet.

Unfortunately you can't do POST requests from an anchor tag, you'll need to do either an AJAX call or do a form submit with the jsonObject as one of the values.

Upvotes: 1

Related Questions