Solved

sending array as request parameter

Posted on 2003-11-09
6
767 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
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bean mapper frameworks 5 60
TreeSet comparator example 7 95
org.apache.jasper.JasperException: using jstl in jsp embedded jetty 13 606
null output 3 25
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Each year, investment in cloud platforms grows more than 20% (https://www.immun.io/hubfs/Immunio_2016/Content/Marketing/Cloud-Security-Report-2016.pdf?submissionGuid=a8d80a00-6fee-4b85-81db-a4e28f681762) as an increasing number of companies begin to…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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