Search code examples
htmljspanchorformshttp-request-parameters

getting value from a link in JSP


I have anchor-link in jsp page as shown below inside the <td> in table.

<td>
    <span>
        <a href="AddDescriptionForEvent.jsp?" name="count"><%=(cnt)%></a>
    <span>
</td>

here cnt inside scriplet is an integer. The tags are in the <form> and action attribute of the <form> is directing to the correct next page.
I have to take the value of that integer in the next page.

I am using like below,

int day = nullIntconv(request.getParameter("count"));

here nullIntconv will convert string to integer.

but I am not getting the value which I selected. It is giving me 0 always.

Kindly suggest.


Solution

  • You need some changes in your href , a href doesn't submit as a form element(eg- textbox,textarea etc..)

    Try using like this..

    <td><span> <a href="AddDescriptionForEvent.jsp?count=<%=(cnt)%>">Click to get count</a><span></td>
    

    In Above count will send as a query string
    On the next page read count from request ...

    String c= request.getParameter("count");
    if(c!=null)
    {
    int count=Integer.parseInt(c);//converting back into integer
    }
    

    -----your custom code here----------