How to pass an array of string in a url

帅比萌擦擦* 提交于 2019-12-08 03:54:40

问题


Hello i have an url in my jsp and i want to pass an array of string in this url to recover in my ActionForm


回答1:


You can use 'standard' html way of passing arrays of data: http://mywebsite/mypage?myarray=value1&myarray=value2&myarray=value3. Then you can fetch all values of parameter myarray from request object (if framework doesn't provide more elegant ways of handling arrays).

But seeing your comment, I would recommend to leave JavaScript and just declare a form for it.
If you need a link (not button), you can always submit form from it. Something like <a href="javascript:$('#myForm').submit();">...</a>




回答2:


If you are dealing with something simple like a list of numeric ids, i would just run through the check boxes, create a comma separated list, and assign it to a query string parameter. On the other side i would split the string. If the values are more complex you have to consider escape characters. Also if you are dealing with a long list, the url is not the best way to pass this data.




回答3:


Try Json encode

http://code.google.com/p/json-simple/

Check this



来源:https://stackoverflow.com/questions/3959609/how-to-pass-an-array-of-string-in-a-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!