Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

creating a UUID using pageContext.setAttribute

843840Mar 20 2008 — edited Mar 20 2008
WARNING NOOB ALERT

So, I would like to create a variable that stores a automatically generated UUID when a user visits a particular page in my app. I did something similar in this same page to also create a time stamp. Here is the code for the time stamp that works:
<% pageContext.setAttribute("time_stamp", (new java.util.Date()).toString()); %>
I got this suggestion by an example I found in my O'Reilly JSP book.

So I am trying to apply this same logic to creating a UUID on this page. The code I'm using (will not compile) is as follows:
<% pageContext.setAttribute("uuid", (new (java.util.UUID.randomUUID()).toString()); %>
Any thoughts on what I am doing wrong here? I understand that java.util.Date() has a constructor without any parameters that allows it to be created in this manor. But there is no constructor for java.util.UUID that doesn't require parameters. Yet, there is this method to generate a random UUID.

I am missing something fundamental here that I would like some light shed on. Can you help? I have tried every combination (that I can think of) of parenthesis etc... I just can't get this to work. Furthermore, I am using Netbeans to write my code and when the autocomplete code suggestions pop up I am given the option to select "randomUUID()" when typed inline in this manor. Thoughts?

Edited by: gnunix on Mar 20, 2008 9:10 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 17 2008
Added on Mar 20 2008
1 comment
798 views