📄 0169.htm
字号:
<html>
<head>
<title>新时代软件教程:操作系统 主页制作 服务器 设计软件 网络技术 编程语言 文字编辑</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
<!--
body, table {font-size: 9pt; font-family: 宋体}
a {text-decoration:none}
a:hover {color: red;text-decoration:underline}
.1 {background-color: rgb(245,245,245)}
-->
</style>
</head>
<p align="center"><script src="../../1.js"></script></a>
<p align="center"><big><strong>cookie操作的例子</strong></big></p>
<div align="right">---摘自互联网</div>
<br><!--<br>
cookie.jsp<br>
<br>
This JSP makes use of 3 custom tags:<br>
One to set a Cookie using attributes that were entered in a submitted form. <setcookie><br>
One to display all the Cookies associated with this request. <getcookies><br>
One to display a single specific Named Cookie <getcookie><br>
<br>
Note the use of <getcookies> to populate the dropdown list rather than for general display.<br>
--><br>
<br>
<%@ taglib uri = "exampleTLD" prefix="ex" %><br>
<%<br>
String errorMessage = "";<br>
String nameToSet = request.getParameter("nameToSet"); //required in order to Set a cookie<br>
String value = request.getParameter("value"); //required in order to Set a cookie<br>
String domain = request.getParameter("domain");<br>
String maxage = request.getParameter("maxage");<br>
String path = request.getParameter("path");<br>
String secure = request.getParameter("secure");<br>
String comment = request.getParameter("comment");<br>
String setACookie = request.getParameter("setACookie");<br>
String getAllCookies = request.getParameter("getAllCookies");<br>
String getACookie = request.getParameter("getACookie");<br>
String nameToGet = request.getParameter("nameToGet"); //required in order to Get a cookie by name.<br>
%><br>
<br>
<html><br>
<head><br>
<title>cookie.jsp</title><br>
</head><br>
<br>
<body><br>
<center><br>
<h1>cookie.jsp</h1><br>
<br>
<% <br>
if( setACookie != null && (nameToSet == null // nameToSet.trim().length() == 0 //<br>
value == null // value.trim().length() == 0) )<br>
errorMessage = ("<font color=red><h1>! Both Name and Value are required to Set a cookie.</h1></font>");<br>
<br>
else if(getACookie != null && (nameToGet == null // nameToGet.trim().length() == 0) )<br>
<br>
errorMessage = ("<font color=red><h1>! A Name is required in order to Get a Cookie by it's name.</h1></font>");<br>
%><br>
<br>
<%= errorMessage %><br>
<br>
<p><br>
<b><br>
You must enter a value for all of the fields which aren't marked as optional.<br><br>
The Comment field can only be used with Version 1 (RFC2109) cookies.<br>
</b><br>
<br>
<br><br>
<br>
<p><br>
<form action=cookie.jsp method=POST><br>
<table><br>
<tr><td><b>Name :</b></td><td><input type=text size=50 name="nameToSet"></td></tr><br>
<tr><td><b>Value :</b></td><td><input type=text size=50 name="value"></td></tr><br>
<tr><td><b>Domain (optional) :</b></td><td><input type=text size=50 name="domain"></td></tr><br>
<tr><td><b>MaxAge (optional):</b></td><td><input type=text size=50 name="maxage"></td></tr><br>
<tr><td><b>Path (optional):</b></td><td><input type=text size=50 name="path"></td></tr><br>
<tr><td><b>Secure (optional):</b></td><td><input type=text size=50 name="secure"></td></tr><br>
<tr><td><b>Comment (optional) :</b></td><td><input type=text size=50 name="comment"></td></tr><br>
</table><br>
<br>
<input type=submit name="setACookie" value="Set A Cookie"> <br>
<input type=reset><br>
<br><br><br><br>
<input type=submit name="getAllCookies" value="Get All Cookies"> <br>
<br><br><br><br>
</form><br>
</p><br>
<br>
<p><br>
<form action=cookie.jsp method=POST><br>
<table border=0><br>
<tr><br>
<td><br>
<b>Name :</b><br>
</td><br>
<br>
<td><br>
<select name="nameToGet"><br>
<ex:getcookies><br>
<option><%=cookieName%><br>
</ex:getcookies><br>
</select><br>
</td><br>
<br>
<td><br>
<input type=submit name="getACookie" value="Get A Cookie By Name"><br>
</td><br>
</tr><br>
</table> <br>
</form> <br>
</p><br>
<br>
<%<br>
if(setACookie != null && (nameToSet != null && nameToSet.trim().length() > 0 &&<br>
value != null && value.trim().length() > 0) )<br>
{ <br>
%><br>
<ex:setcookie name="<%=nameToSet%>" value="<%=value%>" domain="<%=domain%>" maxage="<%=maxage%>" path="<%=path%>" secure="<%=secure%>" comment="<%=comment%>" /> <br>
<% } %> <br>
<br>
<br>
<%<br>
if (getAllCookies != null)<br>
{<br>
//Display all the cookies<br>
%><br>
<br>
<h1>Here are the cookies that were in the Request.</h1><br>
<br>
<table border=1><br>
<th>Name</th><br>
<th>Value</th><br>
<br>
<ex:getcookies><br>
<tr><br>
<td align=center><br>
<%=cookieName%><br>
</td><br>
<td align=center><br>
<%=cookieValue%><br>
</td><br>
</tr><br>
</ex:getcookies><br>
</table><br>
<% } %><br>
<br>
<%<br>
if (getACookie != null && nameToGet != null && nameToGet.trim().length() > 0)<br>
{<br>
//Display a single named cookie<br>
%><br>
<h1>Here is the Cookie you requested.</h1><br>
<br>
<table border=1><br>
<th>Name</th><br>
<th>Value</th><br>
<br>
<ex:getcookie name="<%=nameToGet%>"><br>
<tr><br>
<td align=center><br>
<%=cookieName%><br>
</td><br>
<td align=center><br>
<%=cookieValue%><br>
</td><br>
</tr><br>
</ex:getcookie><br>
</table><br>
<% } %> <br>
<br>
</center><br>
</body><br>
</html>
</table>
<p align="center"><script src="../../2.js"></script></a>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -