Passing session info

hi all,
i have lots of jsp pages and these pages use a lot of class files created by me.
i want to pass session info to class files without having to pass the info through each object that is created in the jsp pages--
what i want to know is that is there any way through which a class file a mine could fetch the session value.(i dont mind passing session info to one class-- but passing to too many classes would be a headache !!)
thanks,
gaurav

Not sure if this will work but worth a try.
Create a class called SessionHolder that looks something like:
public class SessionHolder {
private static HashMap sessionMap;
public synchronized static void putSession(Thread thread, HttpSession session) {
     if (sessionMap == null) { sessionMap = new HashMap(); }
     sessionMap.put(thread, session); }
public synchronized static HttpSession getSession(Thread thread) {
     return (HttpSesion)sessionMap.get(thread); }
public synchronized static void removeSession(Thread thread) {
      sessionMap.remove(thread); }
}<P>
In the servlet you store the session in the SessionHolder via:
SessionHolder.putSession(Thread.currentThread, request.getSession(true));
Always remember to remove the session from the SessionHolder when exiting the servlet or the sessions will linger and take up memory:
SessionHolder.removeSession(Thread.currentThread);
In your classes you can retrieve the session using:
HttpSession session = SessionHolder.getSession(Thread.currentThread);
This should work on the basis that the servlet container will create a new thread for each request to the servlet. As long as your classes do not create new threads they should be able to access the static hashmap to retrieve the session stored by the thread key.
Of course this is just a theory and I have not tested it out to verify if it actually works.

Similar Messages

  • How to pass session info to applet?

    Hi all,
    Is it possible to pass a browers' session id to applet in Tomcat server? I've known that an applet can get a session info from brower.
    Howserver, since I can't chage a applet code I want to modify Tomcat server to maintain session.
    Is there any suggestions?
    thanks.

    The Servlet will normally communicate the session id with a web client (e.g., browser) via cookies. A random session UID is generated and associated with a given client's session. The id is sent back to the client via the http-header set-cookie. On subsequent requests, the browser will include the cookie http-header containing the UID. Some implementations may opt to store the session UID in a hidden form field, though this is less common.
    I'm not sure where the applet is in your architecture. However, if you send and receive HTTP messages, you should be able to store the id and ensure that you send your own requests to the Servlet with the appropriate cookie http-header.
    - Saish

  • Passing Session info between servlets

    We are running WebLogic 5.1, sp 4 and Apache 1.3 on Solaris 2.6 and we are
              successfully proxying requests to the server. But we are unable to pass
              session information between servlets. We are NOT using URL encoding. We are
              instead using cookies. We believe our configuration is correct because the
              BEA example session servlet works. Does anyone have any recommendations or
              suggestions?
              Thank you,
              Jorge
              Jorge A. Martin
              Systems Analyst
              The Kinetic Group
              1950 Stemmons Freeway, Suite 3040
              Dallas, Texas 75207
              

    This is a basic misunderstanding of how Java Works:
    String name +r = request.getParameter(name +r);1) You can't use a + on the left part of an assignment operation - it must be a plain variable reference. This isn't like JavaScript where you have an eval(...) capability.
    2) Your Strings are being defined inside the For Loop, which means they will leave scope once the loop ends and you won't be able to refer to them anymore.
    3) Is there already a String value named 'name' which you are using in getParameters(name+r)? You should probably use getParameter("name"+r) instead.
    What you want to do is either put the values in an array so they are easy to access:
    String name[] = new String[value1];Then loop through the parameters to assign values:
    for(int r = 0; r< value1; r++) { //Start at 0 to value1-1 because arrays are 0 based.
      String nameParam = "name"+ (r+1);
      name[r] = request.getParameter(nameParam);Now I can access the names in order:
    name1 via name[0]
    name2 via name[1]
    name3 via name[2]
    etc...Before going any further I would stop working on Servlets and go back to some good Basic Java Tutorials and books until you get a better grasp of how the language works.

  • Catch BO Session info in Crystal Report 2008 to pass to Xcelsius 2008

    Hi All.
    I have an Xcelsius 2008 model with data provided by a Live Office connection.
    I've tried to embed this model, as swf file, in a report Crystal 2008.
    I've published this report within BOE Enterprise, but trying to visualize it, the Live Office connection prompts for BO authentication.
    Is there any way in Crystal Report 2008 to catch current BO session info to pass it to the Live Office connection?
    I would really appreciate any suggestion.
    Thanks a million.
    PS: I'm sorry if this is not the right forum. This thread is available also in Crystal Reports Design section.

    No, we haven't found a solution that we would like to have.
    We are putting in place a workaround to update the Xcelsius SWF file outside of Crystal.  We will have the Crystal Report using the BOBJ scheduler to export to Excel on a file share the cross tab table used in Xcelsius and then have Xcelsius updated using the BOBJ scheduler.  Instead of having the Xcelsuis embedded in Crystal, the SWF file will be posted to the same SharePoint site that we will be posting the PDF file from Crystal.  Not ideal, but it should work.

  • New insight into my dropdown list problems: loss of session info

    I tried again, this time with NetBeans 5.5.1 (with Tomcat 5.5.17) and stepped through my code; code executed as a result of selecting an item in the second, misbehaving dropdown box.
    I have this function:
        public void prerender() {
            SessionBean1 sb = this.getSessionBean1();
            sb.setPortfolio_id(0);
            this.getDropDown2().setSelected(ddsi);
        }This uses a private data member:
    Object ddsi = null;
    And here is my value changed event handler for this combobox:
        public void dropDown2_processValueChange(ValueChangeEvent event) {
            SessionBean1 sb = this.getSessionBean1();
            String sp_id = (String) this.getDropDown2().getValue();
            ddsi = event.getNewValue();
            String desc = (String) ddsi;
            Long Ldesc = new Long(desc);
            long p_id = Ldesc.longValue();
            sb.setPortfolio_id(p_id); 
            this.getFacesContext().getCurrentInstance().renderResponse();
        }As you can see, I am trying to ensure that the value selected is preserved and used the next time the item is rendered.
    sb.setPortfolio_id(p_id); is a trivial setter function (taking a long argument) for the property portfolio_id.
    When I step through this code, at every step along the way, I see the correct value for p_id! The correct value is passed to the session bean! And I even see the correct value in ddsi when the function "prerender" is executed. However, it seems that this information is lost when the page is actually rendered.
    And, when the servlet that produces the image that is to be displayed on the page checks the session bean, the session bean has the default value (0) for the portfolio_id property rather than the the value (30) that had been passed to the session bean.
    It is as if the session information has been lost, or a new session bean is provided each time the page is rendered.
    The only additional clue is this (found in Tomcat's output);
    com.sun.rave.web.ui.component.DropDown::The current value of component form1:dropDown2 does not match any of the selections.
    Did you forget to reset the value after changing the options?
    Why is this happening? I know full well that at the time the value in dropdown2 is changed, the value in dropdown1 has not, and therefore the value passed to dropDown2 IS in the list of selections. But, when the value in dropDown1 is changed, the list of options in dropDown2 is changed. I wonder if the valueChanged event handler for dropdown1 is being executed every time the page is rendered, forcing dropDown2 to "forget" what was selected, and somehow losing the session info at the same time?????????
    Any ideas?
    Thanks
    Ted

    Upgrading to itunes 7.0 just cost me 2 days of messing around and in the end I had to revert back to v6.0 and resore my lib.
    Apple CS was good but did not belly up the fact that 7.0 is defective in some cases and in the end told me I had a hardware problem!
    The main issue is that I could not get itunes 7.0 to see my ipod (very infrequently after a hard boot I would see it but would not be able to upload anything). Worked(s) 100% with v 6.0.
    This is very defintey 1/2 baked following in the steps of the other well known producers of sw that is not always functional/buggy the first time around.
    My computer is a x40 IBM laptop with xp sp2. Will have to wait a few more weeks to see how this pans out.
    IBM X40 Windows XP

  • Getting Session Info In A Normal Class

    I want to get session info from a class that is not servlet (generally from in a bean). When we use servlets it is so easy to get session info by just using request.getSession() method. Is it possible to get this session info in a normal class which is not servlet Technology?

    Is it possible to get this session info in a normal class which is not >servlet Technology? No reason you cannot.
    But do remember that normal java classes which arent Servlets/Jsps arent invoked by the container as part of the standard request processing.
    Beans, for example, are instantiated (& reused) from within a Servlet or a Jsp.
    So all you have to do is retrieve the session info (or a part thereof) from within a Servlet/Jsp that's part of the request cycle and pass this data onto the bean when you invoke its methods.
    ram.

  • Catch BO Session info in Crystal Report 2008

    Hi All.
    I have an Xcelsius model with data provided by a Live Office connection.
    I've tried to embed this model, as swf file, in a report Crystal 2008.
    I've published this report within BOE Enterprise, but trying to visualize it, the Live Office connection prompts for BO authentication.
    Is there any way in Crystal Report 2008 to catch current BO session info to pass it to the Live Office connection?
    I would really appreciate any suggestion.
    Thanks a million.
    PS: I'm sorry if this is not the right forum. This thread is available also in Dashboard Design (Xcelsius) section.

    HI,
    to get or find an answer/solution about your question/problem?
    I planning also to use Hierarchy Display in CR. And it is very interessting for me to know if that is working.
    Thanks
    Andreas

  • How to pass session variable value with GO URL to override session value

    Hi Gurus,
    We have below requirement.Please help us at the earliest.
    How to pass session variable value with GO URL to override session value. ( It is not working after making changes to authentication xml file session init block creation as explained by oracle (Bug No14372679 : which they claim it is fixed in 1.7 version  Ref No :Bug 14372679 : REQUEST VARIABLE NOT OVERRIDING SESSION VARIABLE RUNNING THRU A GO URL )
    Please provide step by step solution.No vague answers.
    I followed below steps mentioned.
    RPD:
    ****-> Created a session variable called STATUS
    -> Create Session Init block called Init_Status with SQL
        select 'ACTIVE' from dual;
    -> Assigned the session variable STATUS to Init block Init_Status
    authenticationschemas.xml:
    Added
    <RequestVariable source="url" type="informational"
    nameInSource="RE_CODE" biVariableName="NQ_SESSION.STATUS"/>
    Report
    Edit column "Contract Status" and added session variable as
    VALUEOF(NQ_SESSION.STATUS)
    URL:
    http://localhost:9704/analytics/saw.dll?PortalGo&Action=prompt&path=%2Fshared%2FQAV%2FTest_Report_By%20Contract%20Status&RE_CODE='EXPIRED'
    Issue:
    When  I run the URL above with parameter EXPIRED, the report still shows for  ACTIVE only. The URL is not making any difference with report.
    Report is picking the default value from RPD session variable init query.
    could you please let me know if I am missing something.

    Hi,
    Check those links might help you.
    Integrating Oracle OBIEE Content using GO URL
    How to set session variables using url variables | OBIEE Blog
    OBIEE 10G - How to set a request/session variable using the Saw Url (Go/Dashboard) | GerardNico.com (BI, OBIEE, O…
    Thanks,
    Satya

  • Passing Session variable of DATE data type to opaque view filter

    Hi Everyone,
    Can you guys please help me in passing session variable of DATE data type in RPD's physical layer 'opaque view' filter for Oracle database
    I tried following syntax, syntax wise I didn't got getting any error, but at the same time this opaque view is not fetching any records as well. my session variable is "END_DATE" and its value is 1998/12/31:00:00:00(as shown in RPD session windows, datatype is DATETIME)
    SELECT AMOUNT_SOLD, CHANNEL_ID, CUST_ID, PROD_ID, PROMO_ID, QUANTITY_SOLD, TIME_ID FROM SH.SALES
    WHERE TIME_ID =TO_DATE( 'VALUEOF(NQ_SESSION.END_DATE)','MM/DD/YYYY')
    SELECT AMOUNT_SOLD, CHANNEL_ID, CUST_ID, PROD_ID, PROMO_ID, QUANTITY_SOLD, TIME_ID FROM SH.SALES
    WHERE TIME_ID = TO_DATE( 'VALUEOF(NQ_SESSION."END_DATE")','MM/DD/YYYY')
    SELECT AMOUNT_SOLD, CHANNEL_ID, CUST_ID, PROD_ID, PROMO_ID, QUANTITY_SOLD, TIME_ID FROM SH.SALES
    WHERE TRUNC(TIME_ID) = TO_DATE( 'VALUEOF(NQ_SESSION."END_DATE")','MM/DD/YYYY')
    In past, I was able to pass a session variable into a opaque view filter using DATEOF function, but that was in DB2.
    I appreciate your time and help

    Finally, I got right format. here it is
    to_date(substr('valueof(NQ_SESSION.END_DATE)',1,10), 'yyyy-mm-dd')
    and here is the source from where I got this information
    Using OBIEE Session Variables in Select Tables in the Physical Layer

  • Where is the file that contains info on previous session info on a Mac?

    Where is the file that contains info on previous session info on a Mac? I would like to restore several windows and tabs I had open earlier, but the restore previous session menu item does not appear to be available. I had to install and use an older version of Firefox (3.6) to access a website (Fedtraveler.com) that is not compatible with Firefox 6 and is seems to have cleared out the previous session information. I thought I would use Mac OSX Time machine feature to restore the Firefox file where this the previous session info is kept but I don't know what it is called nor how to find it.

    That is the file sessionstore.js in the Firefox Profile Folder.
    *http://kb.mozillazine.org/Profile_folder_-_Firefox
    *http://kb.mozillazine.org/sessionstore.js
    *Help > Troubleshooting Information > Profile Directory: Open Containing Folder

  • Passing session information to multiple JVM's

    Is it possible to pass session information to another JVM running on another server?
    Example:
    Server A calls a servlet on Server B. Will the session object (and values stored in it) created on Server A be accessible to Server B.

    DrClap wrote:
    No.This is not exactly true. If you're talking about a clustered app server implementation (for example, Weblogic supports clustering), where 'machine A' and 'machine B' are both part of the same cluster, then, generally speaking, yes, you're HttpSessions are distributed across those machines.
    God bless,
    -Toby Reyelts

  • Force passing session id in url

    Hello. I need to pass session id (jsessionid) in only url, not in cookies even if cookies are on (accepted). Is it possible?
    I use jboss and struts. Is there any option in xml files?

    ah,
    Scott explained it here
    Why is SESSION used in the URL?

  • Passing Session to Other Java Application

    Dear All,
    We need to pass session of SAP BO to other java application.in short we need to make single sign on between these two without using third party authentication type.
    by research , i could find out extension point API which supports to environment, through which it might be possible.
    I need your help on this.
    Environment:
    SAP BO 4.1 Sp2
    Any Help on this would be appreciated.
    Best Regards,
    Atulm

    Hi all, i have one problem. I need to pass some
    session to a java bean for processing.. Can i know are
    there any possible ways of passing? thanks.if i understand you correctly, and you mean passing a session object
    to a bean from a jsp page, do this:
    have in your bean:
    import javax.servlet.http.HttpSession;
    private HttpSession session = null;
    public void setSession (HttpSession sessionFromJsp) {
    session = sessionFromJsp;
    in your jsp:
    beanname.setSession(session);
    the variable named session is available is jsp pages,
    it is an instance of the javax.servlet.http.HttpSession class,
    and provides access to the client session information.
    dave

  • Passing user info into precompiled flex2 .swf

    Hello all,
    Using flex builder to precompile my .swf how do I then pass
    client info to the SWF when a user accesses it? I have information
    like profile_id and user_id that need to accompany all of my remote
    calls, so how do I get them loaded into the swf if it is
    precompiled? We are running CF 7.02. I thought maybe URLLoader to
    hit a .cfm page, but I am wondering if the request would carry any
    header info...no header means I could not identify who made the
    request and then I am back where I started.
    Thanks for any Help.
    -Mark

    Thanks inlineblue. that is exactly what i was looking for.
    Although now am curious if there is any way to pass an object into
    the swf. My guess is no...not on the init, but if anyone knows how
    to, that would be great.
    I know how to pass objects through remoting, just not on the
    init. I could loop over the struct (it is really a named array) and
    create name value pairs, but I was hoping to avoid that.

  • Session info via audititng and System trigger?

    Hi,
    I am using the following logon trigger to store all the session
    information into a table "client_info".
    When ever the user logon , his session information stores in the
    client_info table.This is our requirement.
    And when the session logoff its information will be deleted from
    the table client_inf via Logoff trigger.
    But the problem is that , The information will not be deleted from
    the client info table , if the user logoff abnormally from the
    database.
    How to overcome this issue.
    I am using auditing + logon and logoff trigger in order get the
    session info.
    Any idea will be great.
    Regards
    Bill>>
    >>
    >>
    >>
    CREATE OR REPLACE TRIGGER trg_client_info
    AFTER LOGON ON DATABASE
    BEGIN
    execute immediate
    'INSERT INTO client_info(session_id,client_name,sid,
    serial#,workstation,host_name,logon_time , description)
    select a.sessionid,a.username , b.sid, b.serial#, a.os_username,
    b.machine,b.logon_time,a.comment_text from user_Audit_trail a ,
    V$session b
    where a.sessionid = b.audsid
    and a.username = b.username
    and a.sessionid=userenv(''sessionid'')';
    commit;
    END;
    CREATE OR REPLACE TRIGGER logoff_session
    BEFORE LOGOFF ON DATABASE
    BEGIN
    DELETE from client_info where session_id = userenv('sessionid');
    commit;
    END;

    See here for a similar discussion:
    LOGOFF TRIGGER for getting Ip address info,etc

Maybe you are looking for