Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

sending array as request parameter

Posted on 2003-11-09
6
Medium Priority
?
781 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 28

Accepted Solution

by:
rrz earned 200 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

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
If something goes wrong with Exchange, your IT resources are in trouble.All Exchange server migration processes are not designed to be identical and though migrating email from on-premises Exchange mailbox to Cloud’s Office 365 is relatively simple…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

598 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