Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6572075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:57:39+00:00 2026-05-25T14:57:39+00:00

I am trying to check if a cookie exists on a JSP page using

  • 0

I am trying to check if a cookie exists on a JSP page using the Expression Language.

I have a cookie called persist which is set to either empty string or “checked”.

If would like to check if the persist cookie exists.

I have tried the following:

<c:if test="${cookie.persist == null}">

<c:if test="${empty cookie.persist}">

Both of the above statements are true when the value of the persist cookie is the empty string and false when the value of the cookie is checked.

How do I distinguish between a cookie with the empty string as its value, and a cookie that does not exist.

(Note: I can easily work around this problem by assigning a non empty value to the cookie instead of the empty string.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:57:40+00:00Added an answer on May 25, 2026 at 2:57 pm

    Closest what you can get is to check the cookie name in the request cookie header.

    <c:if test="${fn:contains(header.cookie, 'persist=')}">
    

    However, when there’s another cookie with name foopersist, it fails.

    If your container supports EL 2.2 (all Servlet 3.0 containers like Tomcat 7, Glassfish 3, etc do) then you could just use Map#containsKey().

    <c:if test="${cookie.containsKey('persist')}">
    

    If yours doesn’t, best what you can do is to create an EL function (more concrete declaration example can be found somewhere near bottom of this answer):

    <c:if test="${util:mapContainsKey(cookie, 'persist')}">
    

    with

    public static boolean mapContainsKey(Map<String, Object> map, String key) {
        return map.containsKey(key);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to check if a service exists on a remote machine using the
Essentially I'm trying to set a cookie after a user logs in to persist
I have a cookie that I did using javascript and to check if it
I am trying to check whether the users have a cookie stored in their
I'm trying to check, using an automated discovery tool, when JAR files in remote
I was trying to check out a project from SVN using Eclipse. I tried
Why linq is trying to check second expression anyway? .Where(t => String.IsNullOrEmpty(someNullString) || t.SomeProperty
I am trying to check if I have write access to a specific key
I have made an app which will be a FB page tab. Now I
I am trying to set an auth cookie in OnAuthorization of my custom attribute

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.