-
new HttpSession
Can somebody tell me when and how ( based on what criteria ) the servlet container
decides to create a new HttpSession ?
-
Re: new HttpSession
"horea" <horea@hotmail.com> wrote:
>
>Can somebody tell me when and how ( based on what criteria ) the servlet
container
>decides to create a new HttpSession ?
In this example the jsp is invoking the user session bean and its labeling
it as session. If it doesn't exists the servlet engine will create the httpsession
with the values of the bean and automaticaly binds the session to the user
<%@page import = "jspcourse.UserSession" %>
<jsp:useBean id="userSession" class="jspcourse.UserSession" scope="session"/>
<html>
<head>
<title> Login Session Test </title>
</head>
<body>.....
User Id="<%=userSession.getUserId()%>" <br>
how does it look in servlets?...
if the parameter on getSession is true and the session does not exists yet
on the server, the servelt engine creates a new one.
HttpSession session = req.getSession(true);
String user = (String) session.getValue(catalog.USER_DATA);
if (user == null) {
username = req.getParameter(catalog.USER_DATA);
return;
}
bind the username to a object named catalog.USER_KEY on the server or update
the value.
session.putValue(catalog.USER_KEY, username);
to send the session to a next web component you should use URLencode method.
Hope this helps
Greetings
Alex
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks