📄 sessionservlet.jsp
字号:
<!-- Copyright (c) 1999-2002 by BEA Systems, Inc. All Rights Reserved.-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;CHARSET=iso-8859-1">
<meta name="description" content="BEA WebLogic Server">
<meta name="keywords" content="BEA WebLogic Server">
<title>Session JSP</title>
<LINK REL="stylesheet"
TYPE="text/css"
HREF="wls_examples.css"
TITLE="BEA WebLogic Server">
</head>
<body bgcolor="#ffffff" link="#3366cc" vlink="#9999cc" alink="#0000cc">
<!-- top intro paragraph tables -->
<!-- RED LINE -->
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td width="100%" bgcolor="#ff0000" height="1">
<p class="small"> </p>
</td>
</tr>
</table>
<table border=0 cellspacing="18" cellpadding="0">
<tr>
<td valign="top">
<a HREF="http://www.bea.com"><IMG SRC="images/logo_tm_onwt.jpg" alt="BEA Logo" border="0"></a>
<h3>Session JSP</h3>
</td>
</tr>
</table>
<!-- RED LINE -->
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td width="100%" bgcolor="#ff0000" height="1">
<p class="small"> </p>
</td>
</tr>
</table>
<table border=0 cellspacing="18" cellpadding="0">
<tr>
<td valign="top">
<p>
This JSP demonstrates the use of HTTP sessions. You can add or delete
named values to a session. The same session can be retrieved next time the
user visits the page via a browser cookie. Use this form to see your additions
and deletions at work. Check the code to see how adding and deleting session
name/value pairs works.
</p>
<%
if (request.getParameter("AddValue") != null) {
String nameField = request.getParameter("NameField");
if (nameField != null && nameField.trim().length() > 0)
session.setAttribute(addPrefix(nameField.trim()),
request.getParameter("ValueField"));
} else if (request.getParameter("DeleteValue") != null) {
session.removeAttribute(addPrefix(request.getParameter("NameField")));
}
%>
<center>
<table border=1 cellspacing=2 cellpadding=5 width=400 bgcolor=#EEEEEE>
<th colspan=2>Session<br>
</th>
<tr>
<td><B>Name</B></td>
<td><B>Value</B></td>
</tr>
<%
Enumeration sessionNames = session.getAttributeNames();
String name;
while (sessionNames.hasMoreElements()) {
name = (String)sessionNames.nextElement();
if (!name.startsWith(PREFIX_LABEL)) continue;
if (removePrefix(name).length() < 1) continue;
%>
<tr>
<td><%= removePrefix(name) %></td>
<td><%= "" + session.getAttribute(name) %></td>
</tr>
<%
} // end of while loop for session names
%>
</table>
</center>
<p>
<form method="post" name="SessionServlet" action="SessionServlet.jsp">
<center>
<table border=0 cellspacing=2 cellpadding=5 width=400>
<th>Name to add/delete</th>
<th>Value</th>
<tr>
<td><input type="text" name="NameField"></td>
<td><input type="text" name="ValueField"></td>
</tr>
<tr>
<td colspan=2 align=center><input type="submit" value=" Add " name="AddValue"></td>
</tr>
<tr>
<td colspan=2 align=center><input type="submit" value="Delete" name="DeleteValue"></td>
</tr>
</table>
</center>
</form>
</td>
</tr>
</table>
<br>
<!-- RED LINE -->
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td width="100%" bgcolor="#ff0000" height="1">
<p class="small"> </p>
</td>
</tr>
</table>
<!-- FOOTER -->
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td align="left">
<p class="copyright">Last updated: March 2002</p>
</td>
</tr>
</table>
<table cellspacing="0" cellpadding="0" border="0" width="100%"><!-- RED LINE -->
<tr>
<td width="100%" bgcolor="#ff0000" height="1">
<p class="small"> </p>
</td>
</tr>
</table>
<p class="copyright"><a href="http://www.bea.com">Home</a> |
<a href="http://www.bea.com/about/index.html" target="_top">Corporate Info</a> |
<a href="http://www.bea.com/press/index.html" target="_top">News</a> |
<a href="http://www.bea.com/solutions/index.html" target="_top">Solutions</a> |
<a href="http://www.bea.com/products/index.html" target="_top">Products</a> |
<a href="http://www.bea.com/partners/index.html" target="_top">Partners</a> |
<a href="http://www.bea.com/services.html" target="_top">Services</a> |
<a href="http://www.bea.com/events/index.html" target="_top">Events</a> |
<a href="http://www.bea.com/download.html" target="_top">Download</a> |
<a href="http://www.bea.com/purchase.html" target="_top">How to Buy</a>
<br>Copyright 2002, BEA Systems, Inc. All rights reserved.
<br>Required browser: Netscape 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher.
<br> <a href="http://www.bea.com/contact/index.html" target="_top">Contact BEA</a>
</p>
</body>
</html>
<%!
static final String PREFIX_LABEL="SessionServlet.";
private String removePrefix(String name) {
if (name.startsWith(PREFIX_LABEL))
name = name.substring(PREFIX_LABEL.length());
return name;
}
private String addPrefix(String name) {
if (!name.startsWith(PREFIX_LABEL))
name = PREFIX_LABEL + name;
return name;
}
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -