PROGRAM FOR COOKIES USING JSP

ENTRY.HTML
<html>
<body>
<form  action="cookie.jsp" method="get">

Username: <input type="text" name="username"> <br />
Email:    <input type="text" name="email" />  </br></br>
          <input type="submit" value="Submit" /></br></br></br>

</form>

</body>
</html>

COOKIE.JSP
<%@ page import="java.io.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="javax.servlet.http.Cookie" %>

<html>

<body>

<%
       
   Cookie username = new Cookie("username",
    request.getParameter("username"));
   Cookie email = new Cookie("email",
  request.getParameter("email"));

 
   username.setMaxAge(60*60*10);
   email.setMaxAge(60*60*10);

   // Add both the cookies in the response header.
   response.addCookie( username );
   response.addCookie( email );
%>


<b>Username:</b>
   <%= request.getParameter("username")%></br></br>
<b>Email:</b>
   <%= request.getParameter("email")%>


</body>
</html>
OUTPUT:


No comments:

Post a Comment