Results 1 to 2 of 2
  1. #1
    kalyana is offline Member
    Join Date
    Aug 2010
    Posts
    25
    Rep Power
    0

    Default How to handling submit button from servlet

    hi all.....
    i have problem during handling button from my servlet .when i click button 3 ,
    servlet not forward to outputControl.jsp .But for button1 ,there work well .
    what's the kind problem there ? hope some one can show me the best way to do that .i have a more button in JSP that i want to handle from servlet .
    all help ,would be appreciated.


    code like bellow :
    index.jsp :

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <form name="mainform" action="servletControl" method="POST">
    <input type="submit" value="button1" name="button1" />
    <input type="submit" value="button2" name="button1" />
    <input type="submit" value="button3" name="button3" />
    </form>
    </body>
    </html>

    servletControl :
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    String button1Click = request.getParameter("button1");
    String button3Click = request.getParameter("button3");
    try {
    if(button1Click.equalsIgnoreCase("button1")){
    RequestDispatcher dispatcher = request.getRequestDispatcher("/outputControl.jsp");
    dispatcher.forward( request, response);
    }
    if(button1Click.equalsIgnoreCase("button2")){
    RequestDispatcher dispatcher = request.getRequestDispatcher("/outputControl.jsp");
    dispatcher.forward( request, response);
    }
    if(button3Click.equalsIgnoreCase("button3")){
    RequestDispatcher dispatcher = request.getRequestDispatcher("/outputControl.jsp");
    dispatcher.forward( request, response);
    }
    } finally {
    out.close();
    }
    }

  2. #2
    kalyana is offline Member
    Join Date
    Aug 2010
    Posts
    25
    Rep Power
    0

    Default

    is there any body know ?i have try with different button name and make form /each button .but only work for button 1. i don't know how to solve this ......

    index.jsp :
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <form name="mainform" action="servletControl" method="POST">
    <input type="submit" value="button1" name="button1" />
    </form>
    <form name="mainform" action="servletControl" method="POST">
    <input type="submit" value="button2" name="button2" />
    </form>
    <form name="mainform" action="servletControl" method="POST">
    <input type="submit" value="button3" name="button3" />
    </form>
    </body>
    </html>

    servletControl:
    if(button1Click.equals("button1")){
    RequestDispatcher dispatcher = request.getRequestDispatcher("/outputControl.jsp");
    dispatcher.forward( request, response);
    }
    if(button2Click.equals("button2")){
    RequestDispatcher dispatcher = request.getRequestDispatcher("/outputControl.jsp");
    dispatcher.forward( request, response);
    }
    if(button3Click.equals("button3")){
    RequestDispatcher dispatcher = request.getRequestDispatcher("/outputControl.jsp");
    dispatcher.forward( request, response);
    }

Similar Threads

  1. JSP program to handle submit button
    By gurpreet.singh in forum JavaServer Pages (JSP) and JSTL
    Replies: 6
    Last Post: 03-09-2011, 06:46 AM
  2. passing data to two servlets uing one submit button
    By Cashley in forum Java Servlet
    Replies: 2
    Last Post: 04-12-2010, 02:41 PM
  3. invoking servlet from jsp form submit using web.xml
    By java_hyd in forum Java Servlet
    Replies: 1
    Last Post: 11-24-2009, 09:57 PM
  4. Submit Button Help
    By Jay-1.1 in forum New To Java
    Replies: 2
    Last Post: 05-06-2008, 05:28 PM
  5. Display success message in same page when submit button is clicked
    By am17mu in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-29-2008, 11:56 AM

Posting Permissions

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