Javatpoint Logo
Javatpoint Logo

Java HttpCookie setHttpOnly() 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

Parameter

The above method requires only one parameter:

  1. httpOnly - indicates true if the cookie is HTTP only which means that it is visible as a part of an HTTP request.

Return

N.A.

Example 1

Test it Now

Output:

Check whether the cookie is HTTPOnly: true

Example 2

Test it Now

Output:

Check whether the cookie is HTTPOnly: false

Example 3

Test it Now

Output:

Check whether the first cookie is HTTPOnly:true
Check whether the second cookie is HTTPOnly:false
Next TopicsetMaxAge() Method





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA