Why setMaxAge() and getMaxAge() methods are used in Cookies?

Answers were Sorted based on User's Feedback



Why setMaxAge() and getMaxAge() methods are used in Cookies?..

Answer / abhijitbaji

setMaxAge(), this function sets the maximum age of the
cookie.
The value of the maximum age is the lifetime of the cookie
in seconds.
It is a decimal non-negative integer.
When the age is greater than seconds of maximum age, the
client SHOULD discard the cookie.
A value of zero means the cookie SHOULD be discarded
immediately.


getMaxAge(), this function can be used to retrieve the
maximum age of the cookie.

Is This Answer Correct ?    10 Yes 1 No

Why setMaxAge() and getMaxAge() methods are used in Cookies?..

Answer / tulasi vani

Cookies are created as

Cookie c=new Cookie(name,value);
c.setMaxAge(milliseconds);

int getMaxAge() returns the maximum age of the cookie.

If the value is set to zero it will be deleted
immediately.If the age is a -ve number it states that the
age of the cookie is confined to that particular request
only.

Is This Answer Correct ?    2 Yes 6 No

Post New Answer

More Servlets Interview Questions

Difference between httpservlet and generic servlets?

0 Answers  


what is the difference b/w DispatchAction and LookUpDispatchAction?

1 Answers   Deloitte, iGate, Tech Mahindra,


Explain Action Servlet?

0 Answers   Cap Gemini,


What are the various ways of session supervision in servlets?

0 Answers  


program for RequestDispatcher in servlets?

3 Answers   Wipro,






How can the session in servlet be destroyed?

0 Answers  


Explain in brief the directory structure of a web application?

0 Answers  


Hi Frieds, I am new to servlet why to use servlet in webapplication. what i know is " use servlet as a controller in mvc and to implemnent business logic . is it correct ? One more thing reason for implementing business logic with servlets , why not jsp.

4 Answers  


How do you run a servlet?

0 Answers  


Which event is fired at the time of project deployment and undeployment?

0 Answers  


What are all the protocols supported by httpservlet?

0 Answers  


What is the life cycle of a servlet?

1 Answers  


Categories