title: Set the color of a button on http request from Java Servlet
body: <p>I am trying to develop a webservice where one feature  would be to set the color of a button on a user click. Previously I tried to set this using JavaScript, but am not able to permanently keep the color change  <a href="https://stackoverflow.com/questions/20749200/how-to-change-and-keep-the-color-of-a-button-on-click/20749343?noredirect=1#20749343">(see previous post here)</a>. What I would like to do is have the user select multiple buttons, then submit information based on the buttons selected (like a checkbox, but using buttons to be touch-screen friendly).</p>
  
  <p>How can send information from my Java Servlet to my .jsp file indicating the color of the button? </p>
  
  <p>&lt;---JAVA SERVLET ---></p>
  
  <pre><code>protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  if (request.getParameter("TV1") != null){ 
          toggleButton(1, request);                       
      }
  
  }
  
  public void toggleButton(int targetNum, HttpServletRequest req){
      //button previously selected.. go to deselect..
      if (pressedOnce[targetNum] == true){ 
          pressedOnce[targetNum] = false; 
          req.setAttribute("buttonColor","yellow");
      }
      //button not selected previously.. go to select..
      else{
          targetsSelected[targetNum] = targetNum; //TV1 selected 
          pressedOnce[targetNum] = true;
          req.setAttribute("buttonColor","green");
      }
  }
  </code></pre>
  
  <p>&lt;--- JSP ----></p>
  
  <pre><code>    &lt;style type="text/css"&gt;
      .button {color:green;    
               background-color: &lt;%= request.getAttribute("buttonColor") %&gt;;
               font-size: 150%; 
               font-family: Arial Black;
               width:&lt;%=(buttonWidth+"px")%&gt;; 
               height:&lt;%=(buttonHeight+"px")%&gt;}
  </code></pre>
  
  <p>...</p>
  
  <pre><code>&lt;form action="FirstServlet" method="get"&gt; 
  &lt;div id="TVs"&gt;    
    &lt;%for (int i=1; i&lt;=numTargets; i++) {
   &lt;button id="TV&lt;%=i%&gt;" name= "TV&lt;%=i%&gt;" class="button"&gt; 
  &lt;%}%&gt;
  </code></pre>
  
  <p>Is there a way to set the style class or background color in my JSP from the JavaServlet? When I try to setAttribute("buttonColor", "yellow"); nothing happens. I know I am missing something fundamental here.. but if someone could help me out I'd really appreciate it!</p>