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. 在windwo server2008服务器上配置ftp服务器、及配置phpstrom工具、实现项目同步。

    在windwo server2008服务器上配置ftp服务器.及配置phpstrom工具.实现项目同步. 在windwo server2008服务器上配置ftp服务器 参考该篇文章:http://bl ...

  2. 建立JNI层的本地对象,并与JAVA层交互方法

    最近在做OpenCV4Android开发的时候,需要从摄像头捕获多个图片,传值给本地对象,每次捕获到图片都更新数据,最后将计算得到的数据传给JAVA层,并在界面中显示.经过摸索和调试后,找到了通过本地 ...

  3. 解决 Ajax 发送 post 请求出现 403 Forbidden 的三种方式

    众所周知前端向后台发送 post 请求时,必须验证 csrf,否则会报错 403 Forbidden.使用 Django Form 表单可以直接在表单里面添加 {% csrf_token %} 即可, ...

  4. Linear Algebra - Matrix

    1. 矩阵 定义:有 \(m*n\) 个数 \(a_{ij}(i=1,2,\cdots,m; j=1,2,\cdots,n)\) 排成的 \(m\) 行 \(n\) 列的数表 \[ \begin{Bm ...

  5. Deep Learning - Install the Development Environment

    WLS(Windows Subsystem for Linux) Base WLS Installation Guide Initializing a newly installed distro W ...

  6. 51nod1282(最小表示法&&枚举)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1282 题意:中文题目诶- 思路:指针不可转,刻盘可转,显然,对 ...

  7. cf777D(贪心&&c_str()函数)

    题目链接:http://codeforces.com/contest/777/problem/D 题意:给出n行以#开头的字符串,从原字符串尾部删除尽量少的字符串,使其为非降序排列. 思路:我们可以从 ...

  8. javascript中的style只能取到在HTML中定义的css属性

    如果在css中定义的 li{ width:100px; left:100px; top:; position:absolute; font-style:normal; } 这样执行: oli[0].s ...

  9. CodeForces - 581B-Luxurious Houses

    The capital of Berland has n multifloor buildings. The architect who built up the capital was very c ...

  10. poj1185-炮兵阵地(状态压缩dp)

    炮兵阵地 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25647   Accepted: 9892 Description ...