



CODIGO
<%@page
contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE
HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" %>
<html>
<head>
<meta
http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>cokie input
form</title>
</head>
<body>
<form action="setcokie.jsp"
method="POST">
<p><b>usuario;</b>
<input type="text" name="username"><br>
<input type="submit"
value="enviar">
</form>
</body>
</html>



CODIGO
<%@page contentType="text/html"
pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page
language="java" import="java.util.*" %>
<%
String
username=request.getParameter("username");
if(username==null) username="";
Date now =
new Date();
String
timestamp = now.toString();
Cookie
cookie= new Cookie ("username",username) ;
cookie.setMaxAge(365*24*60*60);
response.addCookie(cookie);
%>
<html>
<head>
<meta
http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>cookjie creada</title>
</head>
<body>
<h2>cookie creada</h2>
<p><a
href="showcookievalue.jsp">siguiente pagina para el valor de la
cookie</a></p>
<p><a
href="index.jsp">regresar</a></p>
</body>
</html>




CODIGO
<%@page contentType="text/html"
pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page
language="java" %>
<%
String
cookieName = "username";
Cookie
cookies [] = request.getCookies();
Cookie
myCookie = null;
if(cookies !=
null){
for(int i
= 0; i < cookies.length; i++){
if(cookies [i].getName(). equals(cookieName)){
myCookie = cookies[i];
break;
}
}
}
%>
<html>
<head>
<meta
http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>shoe save cookie</title>
</head>
<body>
<%
if(myCookie == null){
%>
Falla
<%=cookieName%>
<%
}else{
%>
<p>Bienvenido:
<p><a
href="index.jsp">regresar</a></p><%=myCookie.getValue()%>.
<%
}
%>
</body>
</html>
No hay comentarios.:
Publicar un comentario