Handling Cookies in JSP (I)
31 March 2008Cookies are text files that are downloaded onto a visitor’s hard drive to store the visitor’s actions in order to better
customise their following visits. We may handly cookies in JSP and I will show you how to do that.
JSP provides an implicit response object which is used to add cookies. To add a cookie to the response, addCookie method is used.
We may store useful information in cookies for later use and this method is perfect for our needs.
response.addCookie(Cookie exforsys);
Now I will present a meaningful example to how to set and retrieve cookies. The following form is used to take username form the user. When submitted, it posts the username to setcookies.jsp, which is responsible for storing the information into cookie.
cookieform.jsp
<%@ page language="java" %> <html> <head> <title>Cookie Input Form</title> </head> <body> <form method="post" action="setcookie.jsp"> <p><b>Enter Your Name: </b> <input type="text" name="username"><br> <input type="submit" value="Submit"> </form> </body>
Do read the next posts on this topic.
Related Posts:
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: Handling Cookies in JSP (I)