⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chap1-9.jsp

📁 jsp 主要是界面的jsp的程序的例子
💻 JSP
字号:
<%@ page contentType="text/html;charset=GBK" %>
<%
	request.setCharacterEncoding("GBK");
	String name = request.getParameter("Name");
	String phone = request.getParameter("Phone");
	// 得到所有的Cookie
	Cookie cookies[] = request.getCookies();
	// 如果是上一步提交过来的,则更新Cookie的值
	if(name != null) {
   		Cookie c = new Cookie("Name", name);
	   	c.setMaxAge(30);       // Cookie 的有效期为 30 秒
   		response.addCookie(c);
	}
	else if(cookies != null) { 
		 // 如果已经设置了cookie , 则得到它的值,并保存到变量pName中
   		for(int i=0; i<cookies.length; i++) {
        	if(cookies[i].getName().equals("Name"))
				name = cookies[i].getValue();
   		}
	}
	if(phone != null) {
   		Cookie c = new Cookie("Phone", phone);
   		c.setMaxAge(30);       // Cookie 的有效期为 30 秒
   		response.addCookie(c);
	}
	else if(cookies != null)  { 
		// 如果已经设置了cookie , 则得到它的值,并保存到变量pLove中
   		for(int i=0; i<cookies.length; i++) {
       		if(cookies[i].getName().equals("Phone"))
				phone = cookies[i].getValue();
   		}
	}
%>
<html>
<head>
	<title>使用cookie保存信息</title>
</head>
<body bgcolor="#FFFFFF">
<h2 align="left"><font color="#660000" face="方正舒体">利用 Cookies对象保存信息</font></h2>
<hr>
<form action="chap1-9.jsp" method="POST">
  <p>姓名: 
    <input type="text" size="20" name="Name"    value="<% if(name != null) out.println(name); %>"></p>
  <p>电话: 
    <input name="Phone" type="text" id="Phone"    value="<% if(phone != null) out.println(phone); %>" size="20">
  </p>
    <p><input type="submit" value="保 存">
	<input type="reset" value="取 消">  </p>
</form>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -