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. 如何在模板类中使用这些point类型?

    博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=271 由于PCL模块较多,并且是一个模板库,在一个源文件里包含很多PCL算法 ...

  2. java&nbsp;获取路径与各文件目录的…

    java 获取路径 博客分类: MyJava JavaJSPWebTomcat编程  转至:http://geeksun.iteye.com/blog/356339 (1).request.getRe ...

  3. 使用Axis2方式发布webService的三种方式

    1.Axis2的下载和安装 首先可以下载如下两个zip包:axis2-1.6.1-bin.zipaxis2-1.6.1-war.zip其中 axis2-1.6.1-bin.zip文件中包含了Axis2 ...

  4. javascript 函数属性prototype(转)

    在JavaScript中并没有类的概念,但javascript中的确可以实现重载,多态,继承.这些实现其实方法都可以用JavaScript中的引用和变量作用域结合prototype来解释. 1.pro ...

  5. 从零开始Spring项目

    Spring Boot是什么 SpringBoot是伴随着Spring4.0诞生的: 从字面理解,Boot是引导的意思,SpringBoot帮助开发者快速搭建Spring框架: SpringBoot帮 ...

  6. 给Fitnesse添加调用多参数fixture的调用方法

    修改文件:fitnesse.slim.fixtureInteraction.DefaultInteraction.java 修改如下三处内容: (注意只支持仅含有一个参数,且该参数是多参数的fixtu ...

  7. 在 WinForm/WPF 下制作 Google Material Design 风格程序

    国内社区没有,顺手转.WinForm: https://github.com/IgnaceMaes/MaterialSkin演示:https://www.youtube.com/watch?v=A8o ...

  8. MATLAB求解线性规划

  9. wordcount作业

    搭档:201631062427,201631062627 代码地址:https://gitee.com/oyyyyyy/wordcount 作业地址: 一: 代码互审情况 我们采用的都是c语言的方式完 ...

  10. 2017-9-14 NOIP模拟赛

    送分题 (songfen)e Time Limit: 10 00ms y Memory Limit:128MB题目描述LYK 喜欢干一些有挑战的事, 比如说求区间最大子段和. 它知道这个题目有 O(n ...