href tags in jsp's and passing data by clicking on href tag

39,289

This is because your href elements are simply redirecting to these other pages -- the form's data is scrapped.

What you want to do is allow the form to be submitted -- you will receive the values in your Servlet's doPost() implementation, and in that method, you should then redirect to the page by, perhaps, adding the values in the URL, for instance:

insert.jsp?movie=jaws&hero=hercules&director=spielberg

The values will then be available to that page.

EDIT: based on my latest comment, to do this without POST/servlets, your code would look like that with jQuery enabled:

<form method="get" id="myForm">
    Movie Name :<input type="text" name="movie"/><br>
    Hero:<input type="text" name="hero"><br>
    Director:<input type="text" name="dir"><br>

    <a href="insert.jsp">Insert</a>
    <a href="update.jsp">update</a>
    <a href="delete.jsp">Delete</a>
</form>
<script>
$('#myForm A').click(function(e)
{
   e.preventDefault(); // prevent the link from actually redirecting

   var destination = $(this).attr('href');
   $('#myForm').attr('action', destination);
   $('#myForm').submit();
});
</script>
Share:
39,289
priyatham manne
Author by

priyatham manne

Updated on May 29, 2020

Comments

  • priyatham manne
    priyatham manne about 4 years

    this is my program

    <form method="post">
    Movie Name :<input type="text" name="movie"/><br>
    Hero:<input type="text" name="hero"><br>
    Director:<input type="text" name="dir"><br>
    
    <a href="insert.jsp">Insert</a>
    <a href="update.jsp">update</a>
    <a href="delete.jsp">Delete</a>
    

    when i click on the any of the href link the values of above text boxes should also to be carried to that particular jsp page i used getparameter method but i am not getting what i entered but they are taking null values