1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc)
Java online test
JSP online test
ORACLE online test
Hibernate online test
Servlet online test
Struts online test
EJB online test
C online test
C++ online test
Aptitude online test

Q. How to add and delete Cookie in jsp ?

Add Cookie to response object:
Cookie cookie = new Cookie ("name",value);
cookie.setPath("/");
cookie.setDomain(DOMAIN_NAME); DOMAIN_NAME may be .techfaq360.com
cookie.setMaxAge(2* 7 * 24 * 60 * 60);// 2 week
response.addCookie(cookie);

Get cookie from request object :

Cookie myCookie = null;

Cookie cookies [] = request.getCookies ();
if (cookies != null)
for (int i = 0; i < cookies.length; i++)
{
if (cookies [i].getName().equals ("name")) // the name of the cookie you have added
{
myCookie = cookies[i];
break;
}
}

Delete Cookie:

You can't delete the cookie. just add maxage to 0;
cookie.setMaxAge(0);
cookie.setPath("/");
cookie.setDomain(DOMAIN_NAME);
response.addCookie(cookie);

cookie.setMaxAge(-1) means on browser close cookie will be deleted.

Online Practice Test

Java online test
JSP online test
ORACLE online test
Hibernate online test
Servlet online test
Struts online test
EJB online test
C online test
C++ online test
Aptitude online test

Reviews and Comments


PMP, CAPM, PMI is a registered certification mark of the Project Management Institute, Inc

Copyright © www.techfaq360.com 2016


About US | Contact US | Privacy Policy | Terms and Conditions  | Website disclaimer  | Cancellation and Refund Policy  | Shipping & Delivery Policy