初始提交
diff --git a/tomcat-uid/webapps/examples/servlets/cookies.html b/tomcat-uid/webapps/examples/servlets/cookies.html
new file mode 100644
index 0000000..659a26d
--- /dev/null
+++ b/tomcat-uid/webapps/examples/servlets/cookies.html
@@ -0,0 +1,61 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html>
+<head>
+<title>Untitled Document</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+
+<body bgcolor="#FFFFFF">
+<p><font color="#0000FF"><a href="servlet/CookieExample"><img src="images/execute.gif" align="right" border="0"></a><a href="index.html"><img src="images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
+<h3>Source Code for Cookie Example<font color="#0000FF"><br>
+ </font> </h3>
+<font color="#0000FF"></font>
+<pre><font color="#0000FF">import</font> java.io.*;
+<font color="#0000FF">import</font> javax.servlet.*;
+<font color="#0000FF">import</font> javax.servlet.http.*;
+
+<font color="#0000FF">public class</font> CookieExample <font color="#0000FF">extends</font> HttpServlet {
+
+ <font color="#0000FF">public void</font> doGet(HttpServletRequest request, HttpServletResponse response)
+ <font color="#0000FF">throws</font> IOException, ServletException
+ {
+ response.setContentType("<font color="#009900">text/html</font>");
+ PrintWriter out = response.getWriter();
+
+ <font color="#CC0000">// print out cookies</font>
+
+ Cookie[] cookies = request.getCookies();
+ for (int i = 0; i < cookies.length; i++) {
+ Cookie c = cookies[i];
+ String name = c.getName();
+ String value = c.getValue();
+ out.println(name + "<font color="#009900"> = </font>" + value);
+ }
+
+ <font color="#CC0000">// set a cookie</font>
+
+ String name = request.getParameter("<font color="#009900">cookieName</font>");
+ if (name != null && name.length() > 0) {
+ String value = request.getParameter("<font color="#009900">cookieValue</font>");
+ Cookie c = new Cookie(name, value);
+ response.addCookie(c);
+ }
+ }
+}</pre>
+</body>
+</html>
diff --git a/tomcat-uid/webapps/examples/servlets/helloworld.html b/tomcat-uid/webapps/examples/servlets/helloworld.html
new file mode 100644
index 0000000..e30810a
--- /dev/null
+++ b/tomcat-uid/webapps/examples/servlets/helloworld.html
@@ -0,0 +1,50 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html>
+<head>
+<title>Untitled Document</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+
+<body bgcolor="#FFFFFF">
+<p><font color="#0000FF"><a href="servlet/HelloWorldExample"><img src="images/execute.gif" align="right" border="0"></a><a href="index.html"><img src="images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
+<h3>Source Code for HelloWorld Example<font color="#0000FF"><br>
+ </font> </h3>
+<font color="#0000FF"></font>
+<pre><font color="#0000FF">import</font> java.io.*;
+<font color="#0000FF">import</font> javax.servlet.*;
+<font color="#0000FF">import</font> javax.servlet.http.*;
+
+<font color="#0000FF">public class</font> HelloWorld <font color="#0000FF">extends</font> HttpServlet {
+
+ <font color="#0000FF">public void</font> doGet(HttpServletRequest request, HttpServletResponse response)
+ <font color="#0000FF">throws</font> IOException, ServletException
+ {
+ response.setContentType("<font color="#009900">text/html</font>");
+ PrintWriter out = response.getWriter();
+ out.println("<font color="#009900"><html></font>");
+ out.println("<font color="#009900"><head></font>");
+ out.println("<font color="#009900"><title>Hello World!</title></font>");
+ out.println("<font color="#009900"></head></font>");
+ out.println("<font color="#009900"><body></font>");
+ out.println("<font color="#009900"><h1>Hello World!</h1></font>");
+ out.println("<font color="#009900"></body></font>");
+ out.println("<font color="#009900"></html></font>");
+ }
+}</pre>
+</body>
+</html>
diff --git a/tomcat-uid/webapps/examples/servlets/images/code.gif b/tomcat-uid/webapps/examples/servlets/images/code.gif
new file mode 100644
index 0000000..93af2cd
--- /dev/null
+++ b/tomcat-uid/webapps/examples/servlets/images/code.gif
Binary files differ
diff --git a/tomcat-uid/webapps/examples/servlets/images/execute.gif b/tomcat-uid/webapps/examples/servlets/images/execute.gif
new file mode 100644
index 0000000..f64d70f
--- /dev/null
+++ b/tomcat-uid/webapps/examples/servlets/images/execute.gif
Binary files differ
diff --git a/tomcat-uid/webapps/examples/servlets/images/return.gif b/tomcat-uid/webapps/examples/servlets/images/return.gif
new file mode 100644
index 0000000..af4f68f
--- /dev/null
+++ b/tomcat-uid/webapps/examples/servlets/images/return.gif
Binary files differ
diff --git a/tomcat-uid/webapps/examples/servlets/index.html b/tomcat-uid/webapps/examples/servlets/index.html
new file mode 100644
index 0000000..b778706
--- /dev/null
+++ b/tomcat-uid/webapps/examples/servlets/index.html
@@ -0,0 +1,121 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <meta name="GENERATOR" content="Mozilla/4.61 [en] (WinNT; I) [Netscape]">
+ <meta name="Author" content="Anil K. Vijendran">
+ <title>Servlet Examples</title>
+</head>
+<body bgcolor="#FFFFFF">
+<b><font face="Arial, Helvetica, sans-serif"><font size=+2>Servlet
+Examples with Code</font></font></b>
+<p>This is a collection of examples which demonstrate some of the more
+frequently used parts of the Servlet API. Familiarity with the Java(tm)
+Programming Language is assumed.
+<p>These examples will only work when viewed via an http URL. They will
+not work if you are viewing these pages via a "file://..." URL. Please
+refer to the <i>README</i> file provide with this Tomcat release regarding
+how to configure and start the provided web server.
+<p>Wherever you see a form, enter some data and see how the servlet reacts.
+When playing with the Cookie and Session Examples, jump back to the Headers
+Example to see exactly what your browser is sending the server.
+<p>To navigate your way through the examples, the following icons will
+help:
+<br>
+<table BORDER=0 CELLSPACING=5 WIDTH="85%" >
+<tr VALIGN=TOP>
+<td WIDTH="30"><img SRC="images/execute.gif" ></td>
+
+<td>Execute the example</td>
+</tr>
+
+<tr VALIGN=TOP>
+<td WIDTH="30"><img SRC="images/code.gif" height=24 width=24></td>
+
+<td>Look at the source code for the example</td>
+</tr>
+
+<tr VALIGN=TOP>
+<td WIDTH="30"><img SRC="images/return.gif" height=24 width=24></td>
+
+<td>Return to this screen</td>
+</tr>
+</table>
+
+<p>Tip: To see the cookie interactions with your browser, try turning on
+the "notify when setting a cookie" option in your browser preferences.
+This will let you see when a session is created and give some feedback
+when looking at the cookie demo.
+<br>
+<table BORDER=0 CELLSPACING=5 WIDTH="85%" >
+<tr VALIGN=TOP>
+<td>Hello World</td>
+
+<td VALIGN=TOP WIDTH="30%"><a href="servlet/HelloWorldExample"><img SRC="images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="servlet/HelloWorldExample">Execute</a></td>
+
+<td WIDTH="30%"><a href="helloworld.html"><img SRC="images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="helloworld.html">Source</a></td>
+</tr>
+
+<tr VALIGN=TOP>
+<td>Request Info</td>
+
+<td WIDTH="30%"><a href="servlet/RequestInfoExample"><img SRC="images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="servlet/RequestInfoExample">Execute</a></td>
+
+<td WIDTH="30%"><a href="reqinfo.html"><img SRC="images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="reqinfo.html">Source</a></td>
+</tr>
+
+<tr VALIGN=TOP>
+<td>Request Headers</td>
+
+<td WIDTH="30%"><a href="servlet/RequestHeaderExample"><img SRC="images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="servlet/RequestHeaderExample">Execute</a></td>
+
+<td WIDTH="30%"><a href="reqheaders.html"><img SRC="images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="reqheaders.html">Source</a></td>
+</tr>
+
+<tr VALIGN=TOP>
+<td>Request Parameters</td>
+
+<td WIDTH="30%"><a href="servlet/RequestParamExample"><img SRC="images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="servlet/RequestParamExample">Execute</a></td>
+
+<td WIDTH="30%"><a href="reqparams.html"><img SRC="images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="reqparams.html">Source</a></td>
+</tr>
+
+<tr VALIGN=TOP>
+<td>Cookies</td>
+
+<td WIDTH="30%"><a href="servlet/CookieExample"><img SRC="images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="servlet/CookieExample">Execute</a></td>
+
+<td WIDTH="30%"><a href="cookies.html"><img SRC="images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="cookies.html">Source</a></td>
+</tr>
+
+<tr VALIGN=TOP>
+<td>Sessions</td>
+
+<td WIDTH="30%"><a href="servlet/SessionExample"><img SRC="images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="servlet/SessionExample">Execute</a></td>
+
+<td WIDTH="30%"><a href="sessions.html"><img SRC="images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="sessions.html">Source</a></td>
+</tr>
+</table>
+
+<p>Note: The source code for these examples does not contain all of the
+source code that is actually in the example, only the important sections
+of code. Code not important to understand the example has been removed
+for clarity.
+</body>
+</html>
diff --git a/tomcat-uid/webapps/examples/servlets/reqheaders.html b/tomcat-uid/webapps/examples/servlets/reqheaders.html
new file mode 100644
index 0000000..4cb80c2
--- /dev/null
+++ b/tomcat-uid/webapps/examples/servlets/reqheaders.html
@@ -0,0 +1,49 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html>
+<head>
+<title>Untitled Document</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+
+<body bgcolor="#FFFFFF">
+<p><font color="#0000FF"><a href="servlet/RequestHeaderExample"><img src="images/execute.gif" align="right" border="0"></a><a href="index.html"><img src="images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
+<h3>Source Code for RequestHeader Example<font color="#0000FF"><br>
+ </font> </h3>
+<font color="#0000FF"></font>
+<pre><font color="#0000FF">import</font> java.io.*;
+<font color="#0000FF">import</font> java.util.*;
+<font color="#0000FF">import</font> javax.servlet.*;
+<font color="#0000FF">import</font> javax.servlet.http.*;
+
+<font color="#0000FF">public class</font> RequestHeaderExample <font color="#0000FF">extends</font> HttpServlet {
+
+ <font color="#0000FF">public void</font> doGet(HttpServletRequest request, HttpServletResponse response)
+ <font color="#0000FF">throws</font> IOException, ServletException
+ {
+ response.setContentType("<font color="#009900">text/html</font>");
+ PrintWriter out = response.getWriter();
+ Enumeration e = request.getHeaderNames();
+ while (e.hasMoreElements()) {
+ String name = (String)e.nextElement();
+ String value = request.getHeader(name);
+ out.println(name + "<font color="#009900"> = </font>" + value);
+ }
+ }
+}</pre>
+</body>
+</html>
diff --git a/tomcat-uid/webapps/examples/servlets/reqinfo.html b/tomcat-uid/webapps/examples/servlets/reqinfo.html
new file mode 100644
index 0000000..4ac664b
--- /dev/null
+++ b/tomcat-uid/webapps/examples/servlets/reqinfo.html
@@ -0,0 +1,68 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html>
+<head>
+<title>Untitled Document</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+
+<body bgcolor="#FFFFFF">
+<p><font color="#0000FF"><a href="servlet/RequestInfoExample"><img src="images/execute.gif" align="right" border="0"></a><a href="index.html"><img src="images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
+<h3>Source Code for Request Info Example<font color="#0000FF"><br>
+ </font> </h3>
+<font color="#0000FF"></font>
+<pre><font color="#0000FF">import</font> java.io.*;
+<font color="#0000FF">import</font> javax.servlet.*;
+<font color="#0000FF">import</font> javax.servlet.http.*;
+
+<font color="#0000FF">public class</font> RequestInfo <font color="#0000FF">extends</font> HttpServlet {
+
+ <font color="#0000FF">public void</font> doGet(HttpServletRequest request, HttpServletResponse response)
+ <font color="#0000FF">throws</font> IOException, ServletException
+ {
+ response.setContentType("<font color="#009900">text/html</font>");
+ PrintWriter out = response.getWriter();
+ out.println("<font color="#009900"><html></font>");
+ out.println("<font color="#009900"><body></font>");
+ out.println("<font color="#009900"><head></font>");
+ out.println("<font color="#009900"><title>Request Information Example</title></font>");
+ out.println("<font color="#009900"></head></font>");
+ out.println("<font color="#009900"><body></font>");
+ out.println("<font color="#009900"><h3>Request Information Example</h3></font>");
+ out.println("<font color="#009900">Method: </font>" + request.getMethod());
+ out.println("<font color="#009900">Request URI: </font>" + request.getRequestURI());
+ out.println("<font color="#009900">Protocol: </font>" + request.getProtocol());
+ out.println("<font color="#009900">PathInfo: </font>" + request.getPathInfo());
+ out.println("<font color="#009900">Remote Address: </font>" + request.getRemoteAddr());
+ out.println("<font color="#009900"></body></font>");
+ out.println("<font color="#009900"></html></font>");
+ }
+
+<font color="#FF0000"> /**
+ * We are going to perform the same operations for POST requests
+ * as for GET methods, so this method just sends the request to
+ * the doGet method.
+ */</font>
+
+ <font color="#0000FF">public void</font> doPost(HttpServletRequest request, HttpServletResponse response)
+ <font color="#0000FF">throws</font> IOException, ServletException
+ {
+ doGet(request, response);
+ }
+}</pre>
+</body>
+</html>
diff --git a/tomcat-uid/webapps/examples/servlets/reqparams.html b/tomcat-uid/webapps/examples/servlets/reqparams.html
new file mode 100644
index 0000000..b0de031
--- /dev/null
+++ b/tomcat-uid/webapps/examples/servlets/reqparams.html
@@ -0,0 +1,78 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html>
+<head>
+<title>Untitled Document</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+
+<body bgcolor="#FFFFFF">
+<p><font color="#0000FF"><a href="servlet/RequestParamExample"><img src="images/execute.gif" align="right" border="0"></a><a href="index.html"><img src="images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
+<h3>Source Code for Request Parameter Example<font color="#0000FF"><br>
+ </font> </h3>
+<font color="#0000FF"></font>
+<pre><font color="#0000FF">import</font> java.io.*;
+<font color="#0000FF">import</font> java.util.*;
+<font color="#0000FF">import</font> javax.servlet.*;
+<font color="#0000FF">import</font> javax.servlet.http.*;
+
+<font color="#0000FF">public class</font> RequestParamExample <font color="#0000FF">extends</font> HttpServlet {
+
+ <font color="#0000FF">public void</font> doGet(HttpServletRequest request, HttpServletResponse response)
+ <font color="#0000FF">throws</font> IOException, ServletException
+ {
+ response.setContentType("<font color="#009900">text/html</font>");
+ PrintWriter out = response.getWriter();
+ out.println("<font color="#009900"><html></font>");
+ out.println("<font color="#009900"><head></font>");
+ out.println("<font color="#009900"><title>Request Parameters Example</title></font>");
+ out.println("<font color="#009900"></head></font>");
+ out.println("<font color="#009900"><body></font>");
+ out.println("<font color="#009900"><h3>Request Parameters Example</h3></font>");
+ out.println("<font color="#009900">Parameters in this request:<br></font>");
+ if (firstName != null || lastName != null) {
+ out.println("<font color="#009900">First Name:</font>");
+ out.println("<font color="#009900"> = </font>" + HTMLFilter.filter(firstName) + "<font color="#009900"><br></font>");
+ out.println("<font color="#009900">Last Name:</font>");
+ out.println("<font color="#009900"> = </font>" + HTMLFilter.filter(lastName));
+ } else {
+ out.println("<font color="#009900">No Parameters, Please enter some</font>");
+ }
+ out.println("<font color="#009900"><P></font>");
+ out.print("<font color="#009900"><form action=\"</font>");
+ out.print("<font color="#009900">RequestParamExample\" </font>");
+ out.println("<font color="#009900">method=POST></font>");
+ out.println("<font color="#009900">First Name:</font>");
+ out.println("<font color="#009900"><input type=text size=20 name=firstname></font>");
+ out.println("<font color="#009900"><br></font>");
+ out.println("<font color="#009900">Last Name:</font>");
+ out.println("<font color="#009900"><input type=text size=20 name=lastname></font>");
+ out.println("<font color="#009900"><br></font>");
+ out.println("<font color="#009900"><input type=submit></font>");
+ out.println("<font color="#009900"></form></font>");
+ out.println("<font color="#009900"></body></font>");
+ out.println("<font color="#009900"></html></font>");
+ }
+
+ <font color="#0000FF">public void</font> doPost(HttpServletRequest request, HttpServletResponse res)
+ <font color="#0000FF">throws</font> IOException, ServletException
+ {
+ doGet(request, response);
+ }
+}</pre>
+</body>
+</html>
diff --git a/tomcat-uid/webapps/examples/servlets/sessions.html b/tomcat-uid/webapps/examples/servlets/sessions.html
new file mode 100644
index 0000000..65fc7fd
--- /dev/null
+++ b/tomcat-uid/webapps/examples/servlets/sessions.html
@@ -0,0 +1,70 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html>
+<head>
+<title>Untitled Document</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+
+<body bgcolor="#FFFFFF">
+<p><font color="#0000FF"><a href="servlet/SessionExample"><img src="images/execute.gif" align="right" border="0"></a><a href="index.html"><img src="images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
+<h3>Source Code for Session Example<font color="#0000FF"><br>
+ </font> </h3>
+<font color="#0000FF"></font>
+<pre><font color="#0000FF">import</font> java.io.*;
+<font color="#0000FF">import</font> java.util.*;
+<font color="#0000FF">import</font> javax.servlet.*;
+<font color="#0000FF">import</font> javax.servlet.http.*;
+
+<font color="#0000FF">public class</font> SessionExample <font color="#0000FF">extends</font> HttpServlet {
+
+ <font color="#0000FF">public void</font> doGet(HttpServletRequest request, HttpServletResponse response)
+ <font color="#0000FF">throws</font> IOException, ServletException
+ {
+ response.setContentType("<font color="#009900">text/html</font>");
+ PrintWriter out = response.getWriter();
+
+ HttpSession session = request.getSession(true);
+
+ <font color="#CC0000">// print session info</font>
+
+ Date created = new Date(session.getCreationTime());
+ Date accessed = new Date(session.getLastAccessedTime());
+ out.println("<font color="#009900">ID </font>" + session.getId());
+ out.println("<font color="#009900">Created: </font>" + created);
+ out.println("<font color="#009900">Last Accessed: </font>" + accessed);
+
+ <font color="#CC0000">// set session info if needed</font>
+
+ String dataName = request.getParameter("<font color="#009900">dataName</font>");
+ if (dataName != null && dataName.length() > 0) {
+ String dataValue = request.getParameter("<font color="#009900">dataValue</font>");
+ session.setAttribute(dataName, dataValue);
+ }
+
+ // print session contents
+
+ Enumeration e = session.getAttributeNames();
+ while (e.hasMoreElements()) {
+ String name = (String)e.nextElement();
+ String value = session.getAttribute(name).toString();
+ out.println(name + " <font color="#009900">= </font>" + value);
+ }
+ }
+}</pre>
+</body>
+</html>