ayampenyet
ayampenyet

Reputation: 241

Bringing value of hyperlink from jsp page to servlet

I have a jsp page which displays a list of hyperlinks using a for loop. I want to bring the value of the hyperlink (the list of hyperlinks have different values as they are from an arraylist) across to my servlet, so that the values of each hyperlink will be distinct.

I tried using request.getSession.setAttribute("value",list.get(0)) but I realised that it would only take the last value in the list so the value being brought across remains the same for all hyperlinks.

Any advice on that?

My code is as below.

 <% List<ArrayList> transactions = (List<ArrayList>) request.getAttribute("transactions");
     int count = 0;         
     for (Object o : transactions) 
     {
       count++;
       String status;
       ArrayList list = (ArrayList) o;               
  %>

     <a href="anotherjsppage"><%=list.get(0) //how to bring this value to servlet%></a><br>
     <%=list.get(1) //some other value to be displayed%><br>
     <%
     }
     %>

Upvotes: 0

Views: 2365

Answers (1)

Bharath R
Bharath R

Reputation: 1531

You can use something like..

<a href="anotherjsppage"><%=list.get(0) //how to bring this value to servlet%></a> 
<input type="hidden" value=<%=list.get(0)%> name="hi"/>

and then use this hidden input and get value by

 request.getParameter("hi"); 

in servlet.

Upvotes: 1

Related Questions