No, it is not possible to pull the user id from the session on the client side, because HTTP security prevents that to stop session hijacking.
I tried storing the user id in a different cookie, but I still had trouble accessing it via JavaScript. You have to make sure the Cookie is not "HttpOnly" or "Secure". But don't do that to your session cookie, or you are putting your users in jeopardy of being session-jacked.
If that doesn't work, try to pass the user id back to the C2 client, you need to pass it back by a HTTP(/AJAX) GET request.
EDIT:
I forgot about direct JavaScript injection. Which is what we use. I forget where I found this method, but it was some obscure website.
For our game, I pass session parameters to the C2 client by direct JavaScript injection using this method:
out.println("function doIt(){");
if(localSess!=null) {
out.println("document.getElementById(\"dispName\").value = \"" + localSess.getDisplayName() + "\";");
out.println("document.getElementById(\"pid\").value = \"" + localSess.getPlayerID() + "\";");
out.println("document.getElementById(\"serverIP\").value = \"" + SP.domain(me) + "\";");
out.println("document.getElementById(\"serverURL\").value = \"" + SP.url(me) + "engine\";");
out.println("document.getElementById(\"serverTimestamp\").value = \"" + System.currentTimeMillis() + "\";");
out.println("document.getElementById(\"capitolStarID\").value = \"" + Coordinate.starIdFromPlanetId(localSess.getCapPlanetID()) + "\";");
}
out.println("}");
[/code:13nup5g8]
Which makes a JavaScript function inside of the index.html file that looks like:
[code:13nup5g8]
function doIt(){
document.getElementById("dispName").value = "username";
document.getElementById("pid").value = "2";
document.getElementById("serverIP").value = "www.ravenheart.ca";
document.getElementById("serverURL").value = "/dev0";
document.getElementById("serverTimestamp").value = "1490642097";
document.getElementById("capitolStarID").value = 65;
}
[/code:13nup5g8]
Then I have a bunch of TextBoxes which have the "ID (optional)" fields named, 'dispName', 'pid', 'serverIP', 'serverURL', 'serverTimestamp', 'capitolStarId' which the doIt functions access to change the values of these TextBoxes.
Then on layout start, I simply do a Browser > Execute JavaScript("doIt();") and it loads all of these parameters from my servlets into the TextBoxes.