[英]send parameter from request through json
How can I resend parameter I received from servlet to servlet using json. 如何使用json将我从servlet接收到的参数重新发送到servlet。
Here's what I mean, I am using this way to pass parameters to servlet 这就是我的意思,我正在使用这种方式将参数传递给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? 但是现在,我想使用json来实现,那么如何从json到达${page}
和${isActivated}
?
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. JSP在将页面发送给客户端之前先对其进行解析,因此您可以在代码中的任何位置使用$ {variables},包括javascript内联。
To store them as a JavaScript object: 要将它们存储为JavaScript对象:
var obj = { page: ${page}, isActivated: ${isActivated} };
To store them as a JSON Object: 要将它们存储为JSON对象:
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. 现在,如果要将其发送到其他Servlet,则需要将JSON对象附加到对该Servlet的POST请求。
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. 不幸的是,您不能从锚标记发出POST请求,您需要执行AJAX调用或使用jsonObject作为值之一提交表单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.