how to create a cookie with confluence 4.2?

Hi, I need to create a cookie in user macro environment, I can use the velocity context parameter $req, but this only work to get a cookie, not for create.

Can I do this?

please help.

3 answers

1 vote
Joseph Clark Atlassian Team Jun 18, 2012

Why do you need to create a cookie? There may be a better solution :-)

I need to make a connection with another server using ajax, But it's not safe, I wanna to create a cookie with a encrypted access code to the other server.

Joseph Clark Atlassian Team Jun 26, 2012

It's not possible to modify the Cookie header when using the JavaScript XMLHttpRequest object to do AJAX calls - see

Maybe com.atlassian.jira.web.util.CookieUtils can help you?

how can I use this in the user macro environment??? can you explain how I can do this?? don't reply a question with another question, please ! XD

Oh, you want to manage cookies on client side?

Maybe it's better to use javascript instead of macro?

You can store cookie like this:

document.cookie =
    "theme=" + encodeURIComponent("blue theme") +
    "; max-age=" + 60*60*24*30 +
    "; path=/;" ;

Also, Atlassian have api for managing cookies - - but it stores all values in one key/value map. But you can try it.

If there is strong requirement to store cookie in macro, then you have to add instance of CookieUtils to Velocity params and then call it like

$cookieUtils.createCookie($name, $value, $req)

Honestly, I didn't try to do that in Confluence macro. But I'm absolutely shure, that it work in Jira's Web Action.

Hope it helps :)

Suggest an answer

Log in or Join to answer
Community showcase
Alexey Matveev
Published Saturday in Jira

How to run Jira in a docker container

Everything below is tested on Ubuntu 17.10. I prefer to use Jira in a docker container because: 1. I can install Jira with a couple of commands. 2. I can start and stop Jira just by starting and s...

95 views 2 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot