title: How can I prevent the shopping cart item from incrementing when the user refresh the page?
body: <p>I made a shopping cart using servlet and jsp but i'm facing a problem which increments the quantity of cart item whenever I refresh the <code>cart</code> page. Actually what i'm doing is passing the particular <code>product ID</code> in the url whenever user click the add to cart button on some product just like <code>addtocart.jsp?id=3</code> and then in according to the id I extract the product from the database and add it in the cart but when I refresh this URL <strong>addtocart?id=3</strong> the whole procedure in this page run again which increments the product quantity everytime of a refresh. 
  How can I solve this problem. Any suggestions?</p>
  
  <p><code>product.jsp</code></p>
  
  <pre><code>&lt;%
   String id = request.getParameter("id");
   Connection con = ConnectionManager.getConnection();
   PreparedStatement ps = con.prepareStatement("Select * from products inner join images using(product_name) "
           + "where product_id=?");
   ps.setString(1,id);
   ResultSet rs= ps.executeQuery();
   rs.next();
  
   String name = rs.getString("product_name");
   String image = rs.getString("image_name");
   String company = rs.getString("company_name");
   String category =  rs.getString("category_name");
   String sub = rs.getString("sub_category_name");
   double price = rs.getDouble("price");
   String summary = rs.getString("summary");
   int hits = rs.getInt("hits");
  
   //out.println(price);
  %&gt;
     &lt;div class="container_16" style="background: #FFF;"&gt;
         &lt;div class="grid_16 productHeading"&gt;
             &lt;h2 class="heading"&gt;&lt;%=name %&gt;- By &lt;%= company %&gt; &lt;%=category%&gt; &lt;/h2&gt;
         &lt;/div&gt;
  
         &lt;div class="grid_10"&gt;
  
               &lt;h5&gt;Category: &lt;a href="#" onclick="return false"&gt;&lt;%= category %&gt; &lt;/a&gt; &gt;
                &lt;a href="#" onclick="return false"&gt;  &lt;%= sub %&gt; &lt;/a&gt;&lt;br/&gt;&lt;br/&gt;
                Priced At &lt;span class="Bigred"&gt;RS. &lt;%=price %&gt;&lt;/span&gt; 
               &lt;/h5&gt;
  
               &lt;h2&gt;Summary Of this Item&lt;/h2&gt;
  
  
                         &lt;div class="grid_5" id="addtocart"&gt;
                             &lt;a href="addToCart.jsp?id=&lt;%=id%&gt;"&gt;
                                Add To Cart
                             &lt;/a&gt;
                             &lt;% if(session.getAttribute("admin")!=null)
                                {
                             %&gt;   
                                &lt;a href="addToCart.jsp?id=&lt;%=id%&gt;"&gt;
                                Edit  
                             &lt;/a&gt;
                            &lt;%              
                              }
                             %&gt;   
                         &lt;/div&gt;
  
                 &lt;br/&gt;
  
               &lt;h6 class="grey"&gt;Summary of &lt;%= name%&gt;&lt;/h6&gt;
                      &lt;p class="info"&gt;
                          &lt;%= summary%&gt;
                      &lt;/p&gt;       
  
         &lt;/div&gt;  
  
         &lt;div class="grid_4" id="pimage"&gt;
             &lt;img src="&lt;%= image%&gt;"&gt;
         &lt;/div&gt;    
  
    &lt;/div&gt;    
  </code></pre>