开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜