In your first servlet, where you gather the user information, the following
code
could be used (in your doGet()- or doPost()-method).

        HttpSession session = request.getSession(true);
        session.setAttribute("userid", new Integer(userID));
        session.setAttribute("password", password);

getSession(true) indicates that a session for the user should be created if
it
doesn't exist; the following two lines add the user information to the
session
object. 'userID' is an int with the user's id, and 'password' (String)
his/her password.

Now, in your second servlet, do something like this to get the data.

        HttpSession session = request.getSession(true);
        int userID = ((Integer)session.getAttribute("userid")).intValue();
        int password = (String)session.getAttribute("password");

For more information, just read the Servlet API documentation.

[ Matthias Carlsson ]
[ Programmer (Java, XML/XSL, CGI/Perl, HTML/JS) ] [ Web Designer ]
[ E-Mail : [EMAIL PROTECTED] ] [ ICQ: 1430647 ]

> -----Ursprungligt meddelande-----
> Fran: A mailing list for discussion about Sun Microsystem's Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]For pramod
> Skickat: den 20 januari 2001 07:08
> Till: [EMAIL PROTECTED]
> Amne: Tell me abt Session
>
>
> hi
>
> i am calling a servlet form antthor servlet. Actully from the calling
> servlet i am passing param to the second servlet. Here the first servlet
> is used for Authentication and i am passing the  userid and password to
> the second servlet. But i think this is not a good practice to pass this
> kind of parm through URL eventhough we uses encription technics. Can any
> body explain how can i use Session to pass variables between servlets.
> What are the issues while using Session mechanism.
>
> Thanks in adv.
>
> by
> pramod
>
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
> __________________________________________________________________
> _________
> To unsubscribe, send email to [EMAIL PROTECTED] and include
> in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to