Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert UUID value to string

Tags:

java

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

like image 876
Basit Avatar asked Apr 13 '12 12:04

Basit


People also ask

How do you get the string representation of UUID?

The toString() method is used to return a String object representing this UUID.

Is UUID a string or int?

The UUID as a 32-character lowercase hexadecimal string. The UUID as a 128-bit integer.

Is UUID a string Java?

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.


1 Answers

This will convert your uniques session id to string

String suuid = UUID.randomUUID().toString();
like image 141
vikiiii Avatar answered Sep 24 '22 23:09

vikiiii