DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2005

    Session data in servlets


    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


  2. #2
    Join Date
    Dec 2005
    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?

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

  3. #3
    Join Date
    Nov 2005
    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, 08:59 AM
  2. Preventing duplicate data?
    By chupacabra in forum VB Classic
    Replies: 5
    Last Post: 08-09-2006, 04:20 PM
  3. OVERSEAS Online Data Entry Information
    By jai in forum Careers
    Replies: 0
    Last Post: 02-20-2003, 11:43 PM
  4. Data Access Strategy
    By Karl Robinson in forum VB Classic
    Replies: 0
    Last Post: 07-16-2001, 01: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
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

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

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.