<p>Is it possible to assign a custom ID to a HTTP session through Servlet API?</p>

<p>I know that session handling from any application server, Tomcat for example, it's enough good to generate unique IDs. But I have custom unique session IDs based on information per user and time, so it won't be repeated.</p>

<p>And I looked at every documentation about session handling but nowhere I find what I need.</p>

<p>It's a requirement for a project, so if it's not possible, I need to know the reasons (or it's only not available through API?).</p>

Um...if you have the code to generate a unique ID, you can just do this:
```
```
/** 
 * The String key of the user id attribute.
 */
public static final String USER_ID_KEY = "userIdKey";

// Set the user attribute (createUniqueUserId's parameters and return type are up to you)
httpSession.setAttribute(USER_ID_KEY, createUniqueUserId());

// Retrieve the user attribute later
httpSession.getAttribute(USER_ID_KEY);
```
```
The HttpSession interface also provides a getId() method, which is documented
here
(copying the documentation for reference):
public java.lang.String getId()
Returns a string containing the unique
identifier assigned to this session.
The identifier is assigned by the
servlet container and is
implementation dependent.
Returns: a
string specifying the identifier
assigned to this session