Basit
Basit

Reputation: 8626

How to convert UUID value to string

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

Upvotes: 21

Views: 90813

Answers (2)

vikiiii
vikiiii

Reputation: 9476

This will convert your uniques session id to string

String suuid = UUID.randomUUID().toString();

Upvotes: 50

Betlista
Betlista

Reputation: 10547

You can call toString() on all Java objects...

Upvotes: 0

Related Questions