FACULTY OF ENGINEERING AND TECHNOLOGY
Department of Computer Engineering
Advanced Java Programming (3160707)
Experiment 8: Implement cookies to store firstname and lastname using Java server pages.
[Link]
<!DOCTYPE html>
<html>
<head>
<title>Form Page</title>
</head>
<body>
<form action="[Link]" method="post">
First Name: <input type="text" name="firstName"><br>
Last Name: <input type="text" name="lastName"><br>
<input type="submit" value="Submit">
</form>
</body>
[Link] code:
<%@ page import="[Link]" %>
<%@ page import="[Link]" %>
<%
String firstName = [Link]("firstName");
String lastName = [Link]("lastName");
Cookie firstNameCookie = new Cookie("firstName", [Link](firstName,
"UTF-8"));
Cookie lastNameCookie = new Cookie("lastName", [Link](lastName, "UTF-
8"));
[Link](3600); // Set cookie age in seconds
[Link](3600); // Set cookie age in seconds
[Link](firstNameCookie);
[Link](lastNameCookie);
[Link]("[Link]");
%>
[Link] code:
<%@ page import="[Link]" %>
<%@ page import="[Link]" %>
<%
String firstName = "";
String lastName = "";
Cookie[] cookies = [Link]();
if (cookies != null) {
for (Cookie cookie : cookies) {
if ([Link]().equals("firstName")) {
firstName = [Link]([Link](), "UTF-8");
} else if ([Link]().equals("lastName")) {
lastName = [Link]([Link](), "UTF-8");
}
Enrollment: 210570107012 Batch–6EC2 A
FACULTY OF ENGINEERING AND TECHNOLOGY
Department of Computer Engineering
Advanced Java Programming (3160707)
}
}
%>
<!DOCTYPE html>
<html>
<head>
<title>Show Name</title>
</head>
<body>
<h2>First Name: <%= firstName %></h2>
<h2>Last Name: <%= lastName %></h2>
</body>
</html>
Output :
(Web page Output)
Enrollment: 210570107012 Batch–6EC2 A