A servlet sends three cookies to the client containing form entries for name, age, and surname with values submitted by the user.
Upon receiving the cookies back from the client, the server needs to store:
- The value of the "name" cookie in a string variable named 'name'
- The value of the "age" cookie in an integer variable named 'age'
- The value of the "surname" cookie in a string variable named 'surname'
Although I have written the following code, it fails to compile without any clear error message:
Cookie cookies[] = request.getCookies();
String name; int age; String surname;
for (int i=0; i<cookies.length; i++) {
If (cookies[i].getName().equals("name"))
name = cookies[i].getValue();
Else If (cookies[i].getName().equals("age"))
age = cookies[i].getValue();
Else If (cookies[i].getName().equals("surname"))
surname = cookies[i].getValue();
There are 3 errors present in this code snippet:
Error: Cannot find symbol. Variable 'getValue' is not recognized in Class Cookie.
Error: Cannot find symbol. Variable 'getValue' is not recognized in Class Cookie.
Error: Cannot find symbol. Variable 'getValue' is not recognized in Class Cookie.