将hashmap从javascript传递给servlet [英] Passing hashmap from javascript to servlet

查看:97
本文介绍了将hashmap从javascript传递给servlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这个问题中接受的解决方案创建了一个简单的hashmap:
如何使用JavaScript / JQuery创建简单的地图

然而,我需要将这个var发送给一个servlet并将它们检索到一个Java HashMap中。我该怎么做。



键是一个字符串,而值是一个数组,例如:

 `[1,'apple,orange,banana'],[2,'apple,peach,banana']`... 

我需要将键1,2和数组加载到Java HashMap 中。



我试图用jquery发布它。其中selectedrows是我的地图

  $。post(url,{id:chosenrows}); 


解决方案

我创建了一个JSON字符串,然后通过ajax发布到servlet并在那里构建HashMap。

I created a simplehashmap using the accepted solution in this question: How to create a simple map using JavaScript/JQuery

I however need to send this var to a servlet and retrieve them onto a Java HashMap. How do I do that.

The key is a string while the value is an array, say like:

`[1,'apple,orange, banana'],[2,'apple,peach, banana']` ...

I need the keys 1,2 and the array loaded onto a Java HashMap.

I tried to post it using jquery. where selectedrows is my map

$.post(url, { id: selectedrows });

解决方案

I creates a JSON string and then sent it via an ajax post to the servlet and build the HashMap there.

这篇关于将hashmap从javascript传递给servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆