Results 1 to 2 of 2
  1. #1
    Marty is offline Member
    Join Date
    May 2007
    Rep Power

    Default save global data in servlets

    sorry about this question but:
    How can I save global data in a servlet?
    For example, I have a bean(userBean) stored in session that contains the user's information. A servlet receive some parameters in HttpRequest object and read others (for example user id) from Bean and I need that the methods that forms servlets read the data from the session

    oSession = request.getSession(true);
    oUser = (UserBean)oSesion.getAttribute("oUser");
    I have to do this in each method to read the bean?????
    Is there any way to avoid this?

    thank you
    Last edited by Marty; 05-31-2007 at 05:57 PM.

  2. #2
    Alan is offline Member
    Join Date
    May 2007
    Rep Power


    with global var do you mean instance vars?
    if it is correct so you have to do this:

    oSession = request.getSession(true);
    oUser = (UserBean)oSession.getAttribute("oUser");
    then you send oSession and oUser as parameters in methods

Similar Threads

  1. How can i save the data Internally(auto save)
    By Rama Koti Reddy in forum AWT / Swing
    Replies: 2
    Last Post: 11-01-2010, 08:31 PM
  2. Save data from Excel sheet to servlet
    By chandu.v in forum Java Servlet
    Replies: 2
    Last Post: 04-10-2008, 01:51 PM
  3. Global constants
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-17-2008, 09:06 AM
  4. Declaring global variables
    By eva in forum New To Java
    Replies: 3
    Last Post: 12-23-2007, 12:11 AM
  5. Replies: 1
    Last Post: 08-06-2007, 02:17 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