Cookie issue with serval client

I try to create cookie to store some value in web browse ,after test with two different browses , I change one of their cookie , I restart another browse , it also change to the same value in first browse.

from java.net import CookiePolicy
import java.net.URI
import java.net.HttpCookie
import system.net
"""
    for left view ,if don't find the stn ,use cookie stn .
"""


uri = java.net.URI("http://127.0.0.1:8088/data/perspective/client/TactBoard")
client = system.net.httpClient()
manager = client.getCookieManager()
cookieStore = manager.getCookieStore()


def SetCookie(name, value, maxAge=365 * 24 * 60 * 60):
    cookie = java.net.HttpCookie(str(name), str(value))
    cookie.setMaxAge(maxAge)
    cookieStore.add(uri, cookie)


def GetCookie(name):
    for cookie in cookieStore.get(uri):
        if cookie.name == name:
            return cookie.value
    return None

I use these code with try License. I want to know the reason is license or not .

You're sharing a single cookie store across all your scripts in a given scope (across the entire gateway). Cookies are stored there, and completely independent from browser cookie mechanisms, which are not accessible to any supported Perspective scripting mechanism.

What are you actually trying to do? Tell us that and we might be able to give you a better approach.

The trial license doesn't affect the way scripts execute, so it's not a factor here.

I want to store different tagPath(restore to a view's parameter) which different client could show different infomation by cookies , if I use session , it will be lost after browse close ,so I try to use cookies or web localstorage.

So is there any method If I want to store information in every client?

If they each have their own user login, you could store it in a database per user, otherwise not really

OK ,thank you ,I try to use url parameter and create a function decode the parameter to information which I want to get.
Do you know your company will develop the function with web localstorage or not , this is a popular technical in web develop.

No, I don't know. We've talked about it before, but coming up with a good API is challenging since all scripting is happening on the backend.

Its not impoosible (or even hard) to access/write to browsers localstorage with js injection.
But even if you can ... just go to the database.
It will be faster for most usecases anyways, Unless you also handle all the effects in the injected JS... But that will be a big mess to deal with.

1 Like