Using JSP with Buttons

Do something like this:-

    <% 
        if(request.getParameter("buttonName") != null) {
               session.setAttribute("status", "guest");
        }
    %>

    <FORM NAME="form1" METHOD="POST">
        <INPUT TYPE="HIDDEN" NAME="buttonName">
        <INPUT TYPE="BUTTON" VALUE="Button 1" ONCLICK="button1()">
    </FORM>

    <SCRIPT LANGUAGE="JavaScript">
        <!--
        function button1()
        {
            document.form1.buttonName.value = "yes";
            form1.submit();
        } 
        // --> 
    </SCRIPT>

either use:

  1. <input type="submit" value="click"/> and set form action to some servlet/jsp page where you set you'r session attribute
  2. use ajax in onclick button method.

    JQUERY SAMPLE:

    $.ajax({
      url: "srvServlet", //or setJSP.jsp
      success: function(){
        alert ('ok');
      }
    });
    

Tags:

Button

Jsp