如何从jsp向servlet发送ArrayList [英] how to send ArrayList from jsp to servlet

查看:86
本文介绍了如何从jsp向servlet发送ArrayList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从jsp向Servlet发送一个ArrayList并在Servlet中检索该ArrayList. 我正在使用form action=myServlet并将ArrayList作为隐藏参数发送. 但这是行不通的.

I want to send an ArrayList from jsp to Servlet and retrive that ArrayList in Servlet. I am using form action=myServlet and sending ArrayList as an hidden parameter. But it is not working.

如何将数组列表从JSP发送到Servlet.是可能的

How to send arrayList from JSP to Servlet. Is it possiple

推荐答案

如何将数组列表从JSP发送到Servlet.是可能的

How to send arrayList from JSP to Servlet. Is it possiple

是的,肯定有可能,您需要

Yes definitely it is possible, you need to

  • 在请求对象中填充arrayList对象.
  • 检索servlet中的列表.

由于您没有提供信息,无论您使用的是scriptlet还是jstl,因此我假设这些scriptlet.

As you have not provided information whether you are using scriptlets or jstl, I'm assuming the scriptlets.

在您的JSP中,

 request.setAttribute("arrayList", yourListObject);
 RequestDispatcher rd = request.getRequestDispatcher("servletUrlPattern");
 rd.forward(request, response);

在您的servlet中,您可以使用来访问列表

In your servlet, you can access the list using

 List yourList = (List)request.getAttribute("arrayList");

要从您的JSP文件中调用servlet,

To call the servlet from your JSP file,

 <form action = "yourServletUrl" method = "POST">
    //everything in the form here.
     <input type = "submit" name = "submit">
 </form>

按下提交按钮后,您将可以将jsp数据放入其中.

After pressing submit button, you will be able to get your jsp data into it.

这篇关于如何从jsp向servlet发送ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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