Session data in servlets


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Session data in servlets

  1. #1
    Join Date
    Nov 2005
    Posts
    17

    Session data in servlets

    Hi

    We are trying to include our user name variable in our chat program as the nickname session variable that was registered when they logged in.

    We have included the HttpSession session = req.getSession(true); in the servlet.
    In our code we are trying to assign the variable userName as 'session.getAttribute("name")' that was registered when they logged in.

    The problem we have is the the session variable seems to be an object and we need to convert it into a string. How can we do this.

    Basically what we want it (pseudo code):

    String username = session.getAttribute("name");

    I know this session variable exists as i have used it in previous JSP pages.

    Many thanks

    Sambo

  2. #2
    Join Date
    Dec 2005
    Posts
    97
    um...i dont know anything about applets or what your trying to do, but couldnt you just call the .toString() method or type-cast it?

    Code:
    String username = (String)session.getAttribute("name"); //type-casting...may throw an unconvertible error
    //or
    String username = (session.getAttribute("name")).toString(); //call the .toString() method.

  3. #3
    Join Date
    Nov 2005
    Posts
    17
    cheers that did the job

Similar Threads

  1. Why I can't save data in data base?
    By Kurt in forum Java
    Replies: 7
    Last Post: 10-08-2006, 09:59 AM
  2. Preventing duplicate data?
    By chupacabra in forum VB Classic
    Replies: 5
    Last Post: 08-09-2006, 05:20 PM
  3. OVERSEAS Online Data Entry Information
    By jai in forum Careers
    Replies: 0
    Last Post: 02-21-2003, 12:43 AM
  4. Data Access Strategy
    By Karl Robinson in forum VB Classic
    Replies: 0
    Last Post: 07-16-2001, 02:55 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center