Solved

sending array as request parameter

Posted on 2003-11-09
6
762 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

A safe way to clean winsxs folder from your windows server 2008 R2 editions
What is Backup? Backup software creates one or more copies of the data on your digital devices in case your original data is lost or damaged. Different backup solutions protect different kinds of data and different combinations of devices. For e…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now