简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM