title: jsp: how to get value from session?
body: <p>I get an String array from session and I want to show the String from the array.</p>
  
  <p>I know javascript can't get data from session directly. Is there any method I can get the data from session and transfer it to javascrip?</p>
  
  <p>My code as follows:</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  
  &lt;%String[] sele = (String[])session.getAttribute("selections");%&gt;;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;meta http-equiv="Expires" content="0"&gt;
  &lt;meta http-equiv="kiben" content="no-cache"&gt;
  &lt;title&gt;Check List&lt;/title&gt;
  &lt;script language="javascript"  type="text/JavaScript"  src="cookie.js"&gt;
  &lt;/script&gt;
  &lt;script text="text/javascript"&gt;
      {
          var selections = //String array form session
          for(var v=0;v&lt;selections.length;v++){
              fillForm(selections[v]);
          }           
      }
  
          function fillForm(name){
              var checkbox= document.createElement("input");
              checkbox.type="checkbox";
              checkbox.name=name;
              checkbox.value=name;
              checkbox.id=name;
  
              var label = document.createElement("label");
              label.htmlFor="id";
              label.appendChild(document.createTextNode(name));
  
              var container = document.getElementById("checklist");
              container.appendChild(checkbox);
              container.appendChild(label);
              container.appendChild(document.createElement("br"));
  
  
          }
  
            function submitAction(){
                addUserName(document.getElementById("checklist"));
                var elem = document.getElementById("checklist").elements;           
                for(i =0;i&lt;elem.length;i++){
                   elem[i].checked = true;                  
                }
                var form = document.getElementById("checklist");
                form.submit();
            }
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="checklist" action="selection"&gt;
      &lt;/form&gt;
      &lt;Button type="button" onclick="submitAction()" name="submit"&gt;Submit&lt;/button&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>