You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Hari Om <ha...@hotmail.com> on 2003/04/21 23:24:52 UTC

[users@httpd] SESSIONS are NOT Maintained

Hello Everyone!

I am using Servlets, JSP and JDBC for my Web Application.

I am using SESSION Variables. My entry point is Login Screen 
"www.man.com/proj/servlet/login" where user enters USERNAME/PASSWROD.

This FORM calls PROCESS.JAVA Servlet which creates a SESSION for them as 
shown:
-----------------------------------------------------------------------
HttpSession session = req.getSession(true);
String uname = (String)session.getValue("uname");

// code coonects to JDBC and see if they match
// IF MATCH

session.putValue("uname",req.getParameter("username"));
String uid = "";
uid = uid.valueOf(rs.getInt("uid"));
session.putValue("uid",uid);

//I then redirect to MENU Page ....which list options availabe for this 
user.
res.sendRedirect(menuURL);
---------------------------------------------------------------------

on my menu page (MENU.JAVA), I have following:
-----------------------------------------------------------------
HttpSession session = req.getSession(true);
String uname = (String)session.getValue("uname");
String uid =   (String)session.getValue("uid");

if (uname == null)
{
	PRINT ERROR.....
}
-----------------------------------------------------------------

Later then user selects one of the MENU options and it takes to another 
Servlet (say OPT1.JAVA)...

OPT1 Servlet is processed and at the end it displays a LINK which will take 
a User back to MENU.JAVA Page....

But When users clicks this LINK (A HREF) it takes to MENU.JAVA Page but 
shows UNAME as NULL...... How is it possible...? SHOULD IT NOT RETAIN the 
SESSION....?

HOW CAN I RETAIN my PREVIOUS Session Variables...?

Any related informaiton on this is appreciated.

THANKS!






_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*  
http://join.msn.com/?page=features/junkmail


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] SESSIONS are NOT Maintained

Posted by "Geoffrey.W.Halsted" <ge...@orcmacro.com>.
Hari Om

Are you going between two different servlet contexts?  A session is set 
to null every time you visit a different servelt context.  

Hari Om wrote:

> Hello Everyone!
>
> I am using Servlets, JSP and JDBC for my Web Application.
>
> I am using SESSION Variables. My entry point is Login Screen 
> "www.man.com/proj/servlet/login" where user enters USERNAME/PASSWROD.
>
> This FORM calls PROCESS.JAVA Servlet which creates a SESSION for them 
> as shown:
> -----------------------------------------------------------------------
> HttpSession session = req.getSession(true);
> String uname = (String)session.getValue("uname");
>
> // code coonects to JDBC and see if they match
> // IF MATCH
>
> session.putValue("uname",req.getParameter("username"));
> String uid = "";
> uid = uid.valueOf(rs.getInt("uid"));
> session.putValue("uid",uid);
>
> //I then redirect to MENU Page ....which list options availabe for 
> this user.
> res.sendRedirect(menuURL);
> ---------------------------------------------------------------------
>
> on my menu page (MENU.JAVA), I have following:
> -----------------------------------------------------------------
> HttpSession session = req.getSession(true);
> String uname = (String)session.getValue("uname");
> String uid =   (String)session.getValue("uid");
>
> if (uname == null)
> {
>     PRINT ERROR.....
> }
> -----------------------------------------------------------------
>
> Later then user selects one of the MENU options and it takes to 
> another Servlet (say OPT1.JAVA)...
>
> OPT1 Servlet is processed and at the end it displays a LINK which will 
> take a User back to MENU.JAVA Page....
>
> But When users clicks this LINK (A HREF) it takes to MENU.JAVA Page 
> but shows UNAME as NULL...... How is it possible...? SHOULD IT NOT 
> RETAIN the SESSION....?
>
> HOW CAN I RETAIN my PREVIOUS Session Variables...?
>
> Any related informaiton on this is appreciated.
>
> THANKS!
>
>
>
>
>
>
> _________________________________________________________________
> The new MSN 8: smart spam protection and 2 months FREE*  
> http://join.msn.com/?page=features/junkmail
>
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server 
> Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>
>



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org