tags:

views:

28

answers:

1

hi

In my code for an mini online book store i have a following line repeating 5 times with different value for 'name' parameter

<input name="JSP-2" type="submit" value="Buy">

On clicking the button Buy, the application redirects to a file buy.jsp where it gets the value of name and displays corresponding details of the book.

In my buy.jsp, I have included

    <% String bname= request.getParameter("name");
out.print(bname);
%>

But the name doesnt get assigned to bname and it shows the value as null. How do I pass a parameter from the submit type input? Please help.

+1  A: 

You have to pass the parameter in the request. Since you are having a form, and submitting the foem, you can have a hidden field in the form called, say "submitType" and populate it whenever you click the button, using javascript. Then this will be available in the next request.

Somewhere inside the form :
<input type="hidden" name="submitType">

in the submit buttons:
<input name="JSP-2" type="submit" onclick="setType('Buy')">

Javascript: formName is the name of your form

<script>
   function setType(type)
   {
      //formName is the name of your form
      document.formName.submitType.value = type;
   }
</script>
Nivas