Java/JSP/Form Buttons — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
 
м (1 версия)
 
(нет различий)

Текущая версия на 07:10, 1 июня 2010

Jsp form: Using Buttons

<HTML>
    <HEAD>
        <TITLE>Using Buttons</TITLE>
    </HEAD>
    <BODY>
        <% 
            //if(request.getParameter("buttonName") != null) {
            if(request.getParameterNames() != null) {
        %>
            You clicked 
            <%= request.getParameter("buttonName") %>
        <%
            }
        %>
        <FORM NAME="form1" METHOD="POST">
            <INPUT TYPE="HIDDEN" NAME="buttonName">
            <INPUT TYPE="BUTTON" VALUE="Button 1" ONCLICK="button1()">
            <INPUT TYPE="BUTTON" VALUE="Button 2" ONCLICK="button2()">
        </FORM>
        <SCRIPT LANGUAGE="JavaScript">
            <!--
            function button1()
            {
                document.form1.buttonName.value = "button 1"
                form1.submit()
            }    
            function button2()
            {
                document.form1.buttonName.value = "button 2"
                form1.submit()
            }    
            // --> 
        </SCRIPT>
    </BODY>
</HTML>





Using a Reset Button

<HTML>
    <HEAD>
        <TITLE>Using a Reset Button</TITLE>
    </HEAD>
 
    <BODY>
        <H1>Using a Reset Button</H1>
        <FORM ACTION="formAction.jsp" METHOD="POST">
            Please enter your name:
            <INPUT TYPE="TEXT" NAME="text1">
            <BR>
            <INPUT TYPE="SUBMIT" value="Submit">
            <INPUT TYPE="RESET" value="Reset">
        </FORM>
    </BODY>
<HTML>





Using Buttons

//File: index.html
<HTML>
    <HEAD>
        <TITLE>Using Buttons</TITLE>
    </HEAD>
 
    <BODY>
        <H1>Using Buttons</H1>
        <FORM NAME="form1" ACTION="formAction.jsp" METHOD="POST">
            <INPUT TYPE="HIDDEN" NAME="buttonName">
            <INPUT TYPE="BUTTON" VALUE="Button 1" ONCLICK="button1()">
            <INPUT TYPE="BUTTON" VALUE="Button 2" ONCLICK="button2()">
        </FORM>
        <SCRIPT LANGUAGE="JavaScript">
            <!--
               function button1()
               {
                   document.form1.buttonName.value = "button 1"
                   form1.submit()
               }    
               function button2()
               {
                   document.form1.buttonName.value = "button 2"
                   form1.submit()
               }    
            // --> 
        </SCRIPT>
    </BODY>
</HTML>
///////////////////////////////////////////////////////////////////////////
//File: formAction.jsp
<HTML>
    <HEAD>
        <TITLE>Determining Which Button Was Clicked</TITLE>
    </HEAD>
 
    <BODY>
        <H1>Determining Which Button Was Clicked</H1>
        You clicked 
        <%= request.getParameter("buttonName") %>
    </BODY>
</HTML>