使用 AJAX 从 servlet 获取 ArrayList 对象并将其存储为 javascript 数组变量
我有一些 arrayList 对象作为我的 servlet 请求属性。我想将其放入 JSP 页面中的 javascript 变量 中。我这样尝试过。
abc.jsp
<script>
var myList=<% (ArrayList)request.getParameter("list_name") %>;
//do use of myList.....
</script>
但这不起作用。我没有得到数据。
然后尝试了
var myList=<% =(ArrayList)request.getParameter("list_name") %>;
没有成功!
提前致谢..
I have some arrayList objects as my servlet request attribute. I want to get it into my javascript variable which is in a JSP page. I tried like this.
abc.jsp
<script>
var myList=<% (ArrayList)request.getParameter("list_name") %>;
//do use of myList.....
</script>
But this is not working. I am not getting the data.
Then tried with
var myList=<% =(ArrayList)request.getParameter("list_name") %>;
Didnt work!!
Thanks in advance..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于
ArrayList
的toString()
方法会意外地给出所需的结果,因此您可以简单地使用var myList = ${list_name};
。但是第二个代码片段的结果也应该有效,所以我假设您没有将列表设置为请求属性。确保您已:
request.setAttribute("list_name", yourlist);
您还可以尝试
[${fn:join(list_name, ',')}]
或
Since the
toString()
method ofArrayList
would accidentally give the desired result, then you can simply usevar myList = ${list_name};
. But the result of your 2nd snippet should also be working, so I would assume that you don't have the list set as a request attribute.Make sure you've:
request.setAttribute("list_name", yourlist);
in the servletYou can also try
[${fn:join(list_name, ',')}]
or