Hi All,
Here is an example of the use of an httpsession to
set parameters in the users cookie bin.
Enjoy!
Regards,
- DL
<body bgcolor="white">
<h1> test </h1>
<%
String ss = request.getParameter("ss");
out.println("You typed:"+ss);
response.setHeader(
"set-cookie","customerID=1234");
response.setHeader(
"set-cookie","color=blue");
HttpSession hs =
request.getSession(true);
String id = hs.getId();
long t = hs.getLastAccessedTime();
long creationTime =
hs.getCreationTime();
hs.putValue("java is great","ran");
//hs.putValue("login","lyon");
String gc = (String)hs.getValue("goodies");
if (gc == null) gc = "first goodie";
out.println("<p>goodies = "+gc+"<p>");
hs.putValue("goodies", gc +" another goodie");
hs.putValue("vb is not","rum");
hs.putValue("neither is fortran",
"red");
out.println("id="+id+"<p>");
out.println("time="+t+"<p>");
out.println("creationTime="
+creationTime+"<p>");
Object o = hs.getValue("login");
out.println("login ="+o);
String valueArray[]
= hs.getValueNames();
out.println("<p> value names are:");
for (int i=0; i < valueArray.length; i++)
out.println("<p>"+valueArray[i]);
Cookie c = new Cookie(
"password", "foo");
c.setDomain("docjava.com");
c.setPath("/");
c.setSecure(true);
c.setMaxAge(0);
response.addCookie(c);
System.out.println("the Cookie="+c);
%>
<%
//out.println(dl.GetURL.getAsString(
// "docjava"));
java.util.Date d =
new java.util.Date();
%>
<h1> the date is </h1>
<% out.println(d); %>
<jsp:useBean
id='clock'
scope='page'
class='dates.JspCalendar'
type="dates.JspCalendar"
/>
<h1>year=
<%=
clock.getYear()
%>
</h1>
<font size=4>
<ul>
<li> Day of month: is <jsp:getProperty name="clock"
property="dayOfMonth"/>
<li> Year: is <jsp:getProperty name="clock" property="year"/>
<li> Month: is <jsp:getProperty name="clock" property="month"/>
<li> Time: is <jsp:getProperty name="clock" property="time"/>
<li> Date: is <jsp:getProperty name="clock" property="date"/>
<li> Day: is <jsp:getProperty name="clock" property="day"/>
<li> Day Of Year: is <jsp:getProperty name="clock"
property="dayOfYear"/>
<li> Week Of Year: is <jsp:getProperty name="clock"
property="weekOfYear"/>
<li> era: is <jsp:getProperty name="clock" property="era"/>
<li> DST Offset: is <jsp:getProperty name="clock"
property="dSTOffset"/>
<li> Zone Offset: is <jsp:getProperty name="clock"
property="zoneOffset"/>
</ul>
</font>
</body>
</html>
|