I want to generate unique session id for my session. So i used UUID. Here what i did
if (session == null) {
session = httpServletRequest.getSession(true);
session.setAttribute("logedin", "0");
if (!httpServletRequest.isRequestedSessionIdFromCookie()) {
UUID sessionID = UUID.randomUUID();
Cookie sessionCookie = new Cookie("JSESSIONID", "sessionID"); //problem
}
The Cookie constructor accept two strings, how can i convert my UUID to string so it get the UUID value which is unique? Thanks
The toString() method is used to return a String object representing this UUID.
The UUID as a 32-character lowercase hexadecimal string. The UUID as a 128-bit integer.
The fromString() method of UUID class in Java is used for the creation of UUID from the standard string representation of the same. Parameters: The method takes one parameter UUID_name which is the string representation of the UUID. Return Value: The method returns the actual UUID created from the specified string.
This will convert your uniques session id to string
String suuid = UUID.randomUUID().toString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With