Sunday, 4 September 2016

Send data with hyperlink via URL in JSP/JAVA

We all know that we send data to another page using form or using session variables. But, some time we have to send data to another page using hyperlink. Suppose, we have fetched data from database and made id as hyperlink and clicking on it we do some operation like edit, delete or some thing else.

Let's see how we can do it in simple JSP page.



Here you can see update and delete is associated with each record in the form of hyperlink.

Code is-

<td><a href='updaterecord.jsp?srno=<%=rs.getInt(1)%>' target='blank'>Update</td>
<td><a href='deleterecord.jsp?srno=<%=rs.getInt(1)%>' target='blank'>Delete</td>

Using hyperlink we send the srno(primary key- fetched by rs.getInt(1)) of corresponding record to updaterecord.jsp and deleterecord.jsp pages with the help of srno variable.

When we click on update and delete hyperlink the rs.getInt(1) data sent to another page using srno variable via URL. See the URL after clicking on link


 Now on updaterecord.jsp page we can receive srno variable  value using

                  int search=Integer.parseInt(request.getParameter("srno"));

After getting srno of that particular record, we can do anything related to this record.

No comments:

Post a Comment

Change image source dynamically on hyperlink

 Changing image source dynamically using JQuery. Here in this example I have created there hyperlink and stored all images in the same folde...