jsp中session的又一个例子

---摘自互联网

StartPage.jsp


<%@  page  session="true"  %>
<%
//  first  we  will  put  some  test  data  into  the  bean  to  show
//  we  can  get  it  back  out  again  in  another  page!
String  ls_validate  =  "This  is  our  original  session";
session.setAttribute("Validate",  ls_validate);

//  Now  we  will  build  a  string  containing  the  URL  for  the  next  page.
//  We  are  encoding  session  information  into  the  URL  string,  so  as  you
//  move  from  page  to  page,  your  the  Container  will  know  what  session
//  has  been  used.  Without  this  information,  the  container  will
//  start  a  new  session  for  each  page  request.
String  ls_session_id  =  session.getId();
String  ls_encode_url  =  response.encodeURL("NewPage.jsp");
String  ls_normal_url  =  "NewPage.jsp";
%> 

<Html><Head></Head><Body>
Sample  URL  with  encoded  information:  <%=  ls_encode_url  %>  <BR>
Our  Session  id  is  :  <%=  ls_session_id  %><BR><BR>

<ahref='<%=  ls_encode_url  %>'>  Move  to  new  page  and  keep  session  alive</a><BR><BR>
<ahref=  '<%=  ls_normal_url  %>'>  Move  to  new  page  without  encoding  the  URL</a>
</Body></Html>


NewPage.jsp
<Html><Head></Head><Body>
<%@  page  session="true"  %>
The  Current  Session  id  is:  <%=  session.getId()  %> 


Checking  the  value  stored  in  our  validate  attribute:
<%=session.getAttribute("Validate")%>
</Body></Html>