Login.jsp
<form action="rem" method="POST">
Enter Value: <input type="text" name="val" value=""/>
<input type="submit" value="Submit" />
</form>
----------------------------------------------------------------------------------
RemController.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String myValue = request.getParameter("val");
Cookie userCookie = new Cookie("u", myValue);
userCookie.setMaxAge(60*60*24);
response.addCookie(userCookie);
request.getRequestDispatcher("Remember.jsp").forward(request, response);
}
----------------------------------------------------------------------------------
Remember.jsp
<html>
<%
Cookie[] cookies=request.getCookies();
Cookie cookie=null;
if(cookies != null){
for(int i=0; i<cookies.length; i++){
cookie = cookies[i];
System.out.print(cookie.getName()+": ");
System.out.println(cookie.getValue());
}
}
%>
</html>
----------------------------------------------------------------------------------
<form action="rem" method="POST">
Enter Value: <input type="text" name="val" value=""/>
<input type="submit" value="Submit" />
</form>
----------------------------------------------------------------------------------
RemController.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String myValue = request.getParameter("val");
Cookie userCookie = new Cookie("u", myValue);
userCookie.setMaxAge(60*60*24);
response.addCookie(userCookie);
request.getRequestDispatcher("Remember.jsp").forward(request, response);
}
----------------------------------------------------------------------------------
Remember.jsp
<html>
<%
Cookie[] cookies=request.getCookies();
Cookie cookie=null;
if(cookies != null){
for(int i=0; i<cookies.length; i++){
cookie = cookies[i];
System.out.print(cookie.getName()+": ");
System.out.println(cookie.getValue());
}
}
%>
</html>
----------------------------------------------------------------------------------
No comments:
Post a Comment