Results 1 to 5 of 5
  1. #1
    mudit222 is offline Member
    Join Date
    Apr 2010
    Posts
    16
    Rep Power
    0

    Red face how to use user name as a session variable in jsp

    how to store a user name as a session variable through out the session of that user so that i can use taht user name temporarily in that session????:(

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    804
    Rep Power
    6

    Default

    you write the code so that we can give suggestion.
    Ramya:cool:

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    session.setAttribute()?

  4. #4
    ideyatech is offline Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    7
    Rep Power
    0

    Default

    I assume your getting the user name from a form. Here's a sample code.

    Java Code:
    <%
       //username here is the name of the text field which you will get the username from
       String name = request.getParameter("username");
       //sessionName is the variable name you assign to the session variable
       session.setAttribute("sessionName", name);
    %>
    You can call the variable using:
    Java Code:
    <%= session.getAttribute("sessionName") %>

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    Well, yes...if you're using a JSP to do your work for you...which you shouldn't be doing.
    ;)

Similar Threads

  1. [SOLVED] logout user when session expires
    By sanjeevtarar in forum Java Servlet
    Replies: 14
    Last Post: 07-11-2014, 09:16 AM
  2. Replies: 1
    Last Post: 08-27-2009, 11:16 AM
  3. Replies: 2
    Last Post: 12-23-2008, 06:35 PM
  4. how to use session variable in my problem
    By Arif Baig in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-27-2008, 07:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •