Page changes when i submit the form

<form action="/devilmaycry/register?action=addtocart" method="post">            
           <input type="hidden" name="user" value="<%=user%>"/>
           <input type="hidden" name="pid" value="<%=pid%>"/>
           <input type="submit" value="Add to cart" onclick="add();"/>

i am using the above code to submit a form and add a product to cart
the java code it calls is as follows:

 else if(n.equals("addtocart"))
      String user = req.getParameter("user");
      int pid = Integer.parseInt(req.getParameter("pid"));


          pw.println("<h3>Added to cart !!!<h3>");
          pw.println("<h3>Errror , try again <h3><br>");

it does add the product to the table but it changes the jsp page … i tried to use requestDispatcher but the URL has many parameters so i want something else through which i can retain the same page and update the table also

Source: jquery

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.