Results 1 to 2 of 2
  1. #1
    krishkill is offline Member
    Join Date
    May 2010
    Posts
    11
    Rep Power
    0

    Default JSP and Servlet programming

    Hi,

    i have two buttons of type "sumbit" in my JSP page. I made a form method =post to redirect to a servlet. Its something like this

    <form method="post" action="updateCart">

    <input type="submit" name="add_to_cart" value="Add2Cart">
    <input type="submit" name="checkout" value="checkout"></p>

    when some one clicks any of the submit button the servlet will read the value and depending on the button value obtained i want to perform next action.

    My Servlet code is like this

    SERVLET CODE
    --------------------------
    1)String add_to_cart = null;
    2)String checkout = null;

    3)add_to_cart=request.getParameter("add_to_cart"). toString();

    4)checkout = request.getParameter("checkout").toString();

    5)if (add_to_cart.equals("Add2Cart")){
    .... more code
    }

    The problem is If i click add to cart button error is with line 4. if i click checkout error is with line 3.
    If I comment any of the method(i.e., if i either put only line 3 and remove all checkout information or if i put only checkout information and remove add_to_cart information) the code is working, all the redirections caliculations are happening.

    please let me know how to check which button is clicked in a servlet if i have more than one button of type submit in my jsp page.

    Thanks,

  2. #2
    krishkill is offline Member
    Join Date
    May 2010
    Posts
    11
    Rep Power
    0

    Default

    I got it.. I need to use same name field in the jsp page for dis to happen

Similar Threads

  1. how can i link html+servlet+xml to form servlet
    By balachandarr in forum Java Servlet
    Replies: 0
    Last Post: 04-15-2009, 05:06 PM
  2. Servlet to Servlet connection through URLConnection
    By bsrjavaforum in forum Networking
    Replies: 0
    Last Post: 04-01-2009, 05:12 PM
  3. Replies: 1
    Last Post: 12-02-2008, 01:23 AM
  4. Replies: 0
    Last Post: 08-30-2008, 12:52 PM
  5. Replies: 1
    Last Post: 08-07-2007, 04:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •