Menu
- 14. A web application for implementation: The user is first served a login page which takes user's name and password. After Submitting the details the server checks these values against the data from a database and takes the following decisions.
- • If name and password matches, serves a welcome page with user's full name.
- • If name matches and password doesn't match, then serves “password mismatch” page
- • If name is not found in the database, serves a registration page, where user’s full name is asked and on submitting the full name, it stores, the login name, password and full name in the database (hint: use session for storing the submitted login name and password)
Aim: A web application that lists all cookies stored in the browser on clicking “List Cookies” button. Add cookies if necessary
File: listcookie.jsp
<%
// Create cookies for first and last names.
Cookie firstName = new Cookie("first_name", "naresh");
Cookie lastName = new Cookie("last_name", "koenni");
// Set expiry date after 24 Hrs for both the cookies.
firstName.setMaxAge(60*60*24);
lastName.setMaxAge(60*60*24);
// Add both the cookies in the response header.
response.addCookie(firstName);
response.addCookie(lastName);
// Read cookies
Cookie cookie = null;
Cookie[] cookies = null;
// Get an array of Cookies associated with this domain
cookies = request.getCookies();
if (cookies != null) {
out.println("<h2> Found Cookies Name and Value</h2>");
for (int i = 0; i < cookies.length; i++) {
cookie = cookies[i];
out.print("Name : " + cookie.getName() + ", ");
out.print("Value: " + cookie.getValue() + " <br/>");
}
} else {
out.println("<h2>No cookies found</h2>");
}
%>