Solved

sending array as request parameter

Posted on 2003-11-09
6
769 Views
Last Modified: 2010-04-01
I have a jsp page which has a link that takes sends some request parameters to a servlet.

<a href="/servlet?reqParam=paramValue">Click on the Link</a>

My task is to send an array as parameter so that in servlet i can retrieve them as request.getParameterValues("reqParam");

I have already loaded the javascript array, i couldnt figure how to send that javascript array as parameter.

Thanks
0
Comment
Question by:soft_techy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:yapsing
ID: 9711829
String ans[] = request.getParameterValues("ans");

if sending to db

//extract from my program
for(int i=0;i<ans.length;i++)
{
PreparedStatement stmtadd = C.prepareStatement("insert into answer values('"+ans[i]+"',now(),0,?)");
stmtadd.setInt(1,pollid);
stmtadd.executeQuery();
}
0
 
LVL 1

Author Comment

by:soft_techy
ID: 9711908
Yes, but how can i send the array ans[] from my JSP as part of link?
0
 
LVL 1

Expert Comment

by:yapsing
ID: 9711942
sorry, i used a form and a submit button instead.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Accepted Solution

by:
rrz earned 50 total points
ID: 9712268
<script>
var arr = [11,22,33,44];
function sendArray(){
                     document.arrForm.p.value = arr;
                     document.arrForm.submit();
                    }
</script>
<form name="arrForm" action="<%=request.getContextPath()%>/yourServlet" method="post">
<input type="hidden" name="p"/>
</form>
<a href="javascript:sendArray()">Click on the Link</a>  
and in your servlet use,
         PrintWriter out = response.getWriter();
         String[] pa = request.getParameterValues("p");  
         for(int i=0;i<pa.length;i++){
                                   out.println(pa[i]);
0
 

Expert Comment

by:tizay
ID: 9712293
you can use something like this:
<a href="yournextjsp.jsp?darray=ans[]">your link here</a>

then when your in the next jsp page:
 String[] myarr=request.getParameterValues("darray");

hope i helped you on this one.
0
 
LVL 3

Expert Comment

by:applekanna
ID: 9712533
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Facebook has became the #1 social media platform. People share many funny videos there, yet you don't know how to download them? Now you can download Videos from Facebook in just 3 simple steps.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question