In your servlet code, override the doGet() method and use the
HttpServletRequest request object to query on the names of the buttons
(btn_1, btn_2).  The value of the button should be returned, but you can do
an easy 'if not null check' and avoid string comparisons altogether.  When
you have verified a certain button has been pressed, take some action (like
call another method).  Since no two buttons can be clicked at the same time,
this is a pretty safe test.  Here's some code:

public class HandleButtons extends HttpServlet
{
        public void doGet(HttpServletRequest request,
                                HttpServletResponse response)
                                        throws IOException, ServletException
        {
                String btn1 = request.getParameter("btn_1");
                String btn2 = request.getParameter("btn_2");

                if (btn1 != null)
                {
                        // do something for button 1
                }

                else if (btn2 != null)
                {
                        // do something for button 2
                }
        }
}

Something similar to that should be what you're interested in

Erik Sahl
[EMAIL PROTECTED]


> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Jose
> Miguel Rodriguez
> Sent: Monday, March 06, 2000 9:36 AM
> To: [EMAIL PROTECTED]
> Subject: How to know which form button was pressed?
>
>
> Hello all,
>
> I'm developing a mini applications server for internal purposes,
> and now I'm
> facing with a problem: suppose I have the following html code:
>
> <form action=/servlet/.....>
> <input type="SUBMIT" NAME="btn_1" VALUE="First button">
> <input type="SUBMIT" NAME="btn_2" VALUE="Second button">
> </form>
>
> How do I know when user press the 1st or the 2nd button?
>
> Thanks in advanced
>
>
> --
>
>  saludos,
>  jmiguel
>
>  Virtual Software,
>  http://www.virtualsw.es/
>  ICQ 13550064
>
> __________________________________________________________________
> _________
> To unsubscribe, send email to [EMAIL PROTECTED] and include
> in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to