简体   繁体   English

通过json从请求发送参数

[英]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.

相关问题 如何通过 url 和 Z65E8800B5C6800AAD8800B5C6800AAD8800B5C6800AAD896F888B2A62AFCZ 的主体发送请求主体的 json 参数之一为@FCBmapping80AFD3511Z5 - How to send one of the json parameter of a request body through url and rest through body of postman for @Postmapping 从请求中提取json参数 - Extract json parameter from request 如何从请求 header 中获取 user_id 而不是将其作为请求参数传递? 然后通过header发回 - How can I get the user_id from the request header instead of passing it as a request parameter? And then send it back through the header 尝试从Servlet过滤器发回错误json,而不是允许请求通过 - Trying to send back error json from Servlet filter instead of allowing the request to go through 如何通过RestTemplate在头文件中使用自定义参数发送POST请求 - How to send POST request through RestTemplate with custom parameter in header 从android发送json数组作为post参数 - send json array as post parameter from android 通过Post将JSON从Java发送到PHP - Send JSON from Java to PHP through Post 如何从请求参数中获取子json - How to fetch sub json from request parameter 如何通过JSON发送带有多个参数的http请求 - How to send put http request with multiple parameters through JSON 从黑莓手机应用程序发送JSON请求 - Send JSON Request from blackberry application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM