Java HttpCookie parse() Method22 Mar 2025 | 1 min read The parse(String header) method of HttpCookie class is invoked to construct the cookies from set-cookie or set-cookie2 header string. SyntaxParameterThe above method requires only ne parameter:
ReturnThe above method is used to return a List of cookies which are parsed from header line string. ThrowsIllegalArgumentException - if the header string breaks the cookie specification?s syntax or the given cookie name contains some illegal characters. NullPointerException - if the header string is a null. Example 1Output: Exception in thread "main" java.lang.NullPointerException at java.net.HttpCookie.guessCookieVersion(Unknown Source) at java.net.HttpCookie.parse(Unknown Source) at java.net.HttpCookie.parse(Unknown Source) at javatpoint.JavaHttpCookieParseExample1.main(JavaHttpCookieParseExample1.java:10) Example 2Output: Exception in thread "main" java.lang.IllegalArgumentException: Invalid cookie name-value pair at java.net.HttpCookie.parseInternal(Unknown Source) at java.net.HttpCookie.parse(Unknown Source) at java.net.HttpCookie.parse(Unknown Source) at javatpoint.JavaHttpCookieParseExample2.main(JavaHttpCookieParseExample2.java:8) Next TopicsetComment() Method |
Java HttpCookie Method The setHttpOnly(Boolean httpOnly) method of Java HttpCookie class is used to indicate whether the cookie can be considered as HTTPOnly or not. If it is set to true then the cookie cannot be accessed by scripting engines like JavaScript. Syntax public void setHttpOnly(boolean httpOnly) Parameter The...
1 min read
Java HttpCookie Method The method of HttpCookie class is used to return the path on the server for which the browser return the cookie. The cookie will be visible to all the sub paths on the given server. Syntax public String Parameter N.A. Return The above method is used...
1 min read
Java HttpCookie Method The method of HttpCookie class is invoked to return the domain name set for the given cookie. The general form of the domain is set by RFC 2965. Syntax public String Parameter N.A. Return The above method is used to return a string which contains the...
1 min read
Java HttpCookie Method The setCommentURL(String purpose) method of HttpCookie class is used to specify a comment URL which describes the purpose of the cookie. Comment URL is RFC 2965 only. Syntax public void setCommentURL(String purpose) Parameter The above method requires only one method : purpose - which denotes a String...
1 min read
Java HttpCookie Method The method of Java HttpCookie class is used to return the comment which describes the purpose of the cookie. Also, the method may return null if the cookie has no comment. Syntax public String Parameter N.A. Return The above method is used to return a...
1 min read
Java HttpCookie Method The method of Java HttpCookie class is invoked to return the name of the cookie. Once, the cookie is created, the name of the cookie cannot be altered. Syntax public String Parameter N.A. Return The above method is used to return a String which specifies...
1 min read
Java HttpCookie Method The method of HttpCookie class is used to return the discard attribute of the cookie. Syntax public boolean Parameter N.A. Return The above method is used to return a Boolean which represents the cookie?s discard attribute. Example 1 import java.net.HttpCookie; public class JavaHttpcookieSetDiscardExample1 { public static void...
1 min read
Java HttpCookie Method The setDiscard(boolean discard) method of Java HttpCookie class is used to specify whether the given user agent can discard the cookie unconditionally or not. This attribute is RFC 2965 only. Syntax public void setDiscard(boolean discard) Parameter The above method consist of only one parameter: discard- simply indicates...
2 min read
Java HttpCookie Method The method of Java HttpCookie class is invoked to create and return a copy of the object. Syntax public Object Parameter N.A. Return The above method is used to return a clone of the given HTTP cookie. Example 1 import java.net.HttpCookie; public class JavaHttpCookieCloneExample1 { public static void main(String[]...
1 min read
Java HttpCookie Method The setMaxAge(long expiry)method of Java HttpCookie class is used to set the maximum age of the cookie within seconds. The result with a positive value indicates that the cookie will expire after the specified time in seconds. The result with a negative value indicates...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India