responseo3.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<script type="text/javascript">
function resetValue(){
document.getElementById("userName").value="";
document.getElementById("pwd").value="";
}
</script>
<%
String userName=null;
String pwd=null;
Cookie[] cookies=request.getCookies();
for(int i=0;cookies!=null &&i<cookies.length;i++){
if(cookies[i].getName().equals("userNameAndPwd")){
userName=cookies[i].getValue().split("-")[0];
pwd=cookies[i].getValue().split("-")[1];
}
}

if(userName==null){
userName="";
}

if(pwd==null){
pwd="";
}
%>
</head>
<body>

<form action="userLogin.jsp" method="post">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" id="userName" name="userName" value="<%=userName%>"/></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" id="pwd" name="pwd" value="<%=pwd %>" /></td>
</tr>
<tr>
<td>记住密码:</td>
<td><input type="checkbox" id="remember" name="remember" value="remember-me"/></td>
</tr>
<tr>
<td><input type="submit" value="登录"/></td>
<td><input type="button" value="重置" onclick="resetValue()"/></td>
</tr>
</table>
</form>
</body>
</html>

userLogin.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page import="javax.servlet.http.*"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<%
String userName=request.getParameter("userName"); // 获取用户名
String pwd=request.getParameter("pwd"); // 获取密码
String remember=request.getParameter("remember"); // 获取记住密码

if("remember-me".equals(remember)){
Cookie userNameAndPwd=new Cookie("userNameAndPwd",userName+"-"+pwd);
userNameAndPwd.setMaxAge(1*60*60*24*7); // cookie记录一个星期
response.addCookie(userNameAndPwd); // 保存cookie
System.out.println("设置Cookie成功");
}
response.sendRedirect("response03.jsp");
%>

</body>
</html>

jsp另外五大内置对象之response-操作cookie的更多相关文章

  1. jsp另外五大内置对象之response-操作重定向

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  2. jsp另外五大内置对象之response-设置头信息

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  3. jsp另外五大内置对象之-exception

    //有异常的页面 <%@ page language="java" contentType="text/html; charset=utf-8" page ...

  4. jsp另外五大内置对象之config

    //配置web.xml <?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi=&q ...

  5. jsp另外五大内置对象之-out获取缓冲区大小

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  6. jsp另外五大内置对象之out输出

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  7. 今天我们来认识一下JSP的九大内置对象

    虽然现在基本上我们都是使用SpringMVC+AJAX进行开发了Java Web了,但是还是很有必要了解一下JSP的九大内置对象的.像request.response.session这些对象,即便使用 ...

  8. JSP的9大内置对象

    1.概述 JSP的这9个内置对象,都是servlet API实例,即在JSP页面内部,可以直接使用; ps:顺便说下JSP的4大范围: JSP的四种范围,分别为page.request.session ...

  9. 牛客网Java刷题知识点之什么是JSP、JSP有哪些优点、JSP的9大内置对象、JSP的四大域对象、JSP的四种范围

    不多说,直接上干货! https://www.nowcoder.com/ta/review-java/review?tpId=31&tqId=21175&query=&asc= ...

随机推荐

  1. pig ERROR 2997: Encountered IOException. File or directory null does not exist.

    grunt> ls 2014-03-30 19:58:31,344 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 2997: Enc ...

  2. 转:JDBC Request使用方法

    1.   下载mysql jar包 下载mysql jar包 http://dev.mysql.com/downloads/connector/j/ 网盘下载地址:mysql-connector-ja ...

  3. 20.Consent Controller Get请求逻辑实现

    在这里之前讲的这一块的信息就要登场了 需要通过构造函数把这几个注入进来 县引入这三个命名空间 把这三个注入进来,这就是显示依赖 先通过returnUrl拿到这个Request request拿到后,就 ...

  4. JAVA学习笔记——(四)

    今日内容介绍 1.流程控制语句switch 2.数组 3.随机点名器案例 01switch语句解构 * A:switch语句解构 * a:switch只能针对某个表达式的值作出判断,从而决定程序执行哪 ...

  5. VMware S/4 HANA OP 1511虚拟机下载,64G内存限制解决方案

    http://www.itpub.net/thread-2057212-1-1.html S4 HANA OP 1511 Scale Out

  6. HDU - 1176 免费馅饼 DP多种状态转移

    免费馅饼 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内.馅饼如果掉在了 ...

  7. IT兄弟连 JavaWeb教程 jQuery对AJAX的支持经典案例

    案例需求:编写用户登陆页面的验证码模块,在用户进行登陆时,输入验证码后不需要点击提交按钮,使用AJAX异步地向服务器发送验证验证码的请求.如果验证码正确,可以点击提交按钮,如果验证码输入错误,提示用户 ...

  8. C#代码生成器附百度云盘源码地址

    今晚闲着没事,写了个代码生成器,在这里只做个抛砖引玉,后面可以继续扩展功能,下方附百度云盘源码地址. 使用数据库:sqlserver 编译器:vs2015 废话不多说,上界面: 程序主界面: 数据库: ...

  9. according to tld or attribute directive in tag file attribute *** does not accept any expressions

    http://stackoverflow.com/questions/13428788/according-to-tld-or-attribute-directive-in-tag-file-attr ...

  10. day6作业详解

    1.day6题目 1,老男孩好声⾳选秀⼤赛评委在打分的时候呢, 可以进⾏输入. 假设, 老男孩有10个评委. 让10个评委进⾏打分, 要求, 分数必须⼤于5分, 小于10分. 电影投票. 程序先给出⼀ ...