Setting the session when link is clicked in JSP

I have a jsp page which recieves a Map from a java class function. It retireves the element from the map and displays it onto the page as a link. Now what I want to do is whenever any link is clicked then I want to put the map in the session. How can I do that in the same page????
I do not want to already set the session becoz that gives me problem later on.

Ok, I understand what you are trying to do now. Unfortunately, I still don't think you have much choice. Essentially you will only ever have 4 ways of persisting the data:
1. In memory on the server (eg Session)
2. On disk on the server (eg database)
3. In memory on the client (eg Applet or maybe Javascript)
4. On disk on the client (eg signed applet writing to local file system)
The "standard" approach is to store all of this sort of stuff on the server, so you have a choice between 1 and 2.
I assume your "Employee" data is in a database or LDAP directory? (or some form of "on disk" persistence), and you are querying this data store to populate the objects in memory?
If so, there is a way you can avoid persisting in memory for a long time, but because you will have to persist "somewhere" you will only have option 2 left.. on disk.
In the code where you initially retrieve the data from the data store for the first JSP, you can put the Map in the HttpServletRequest object rather than the session (request.setAttribute()), then access this in the first JSP to render the list. When you get to the second JSP however, this object will be out of scope and you won't have access to it anymore so you will have to query the datastore again for the specific record (based on an ID passed from the first JSP). So when you hit "back", the first JSP should execute again and requery the entire list again.
This approach "shifts" the load from a memory load to a disk load (and you will also be affected by database performance issues), so you may not solve your performance desires.
Alternatively, if the list of Employees is the same for all users (ie, it is an entire list and not a "filtered" list based on some search criteria), then you could store the list in memory at "application scope". Basically you would just load the Map on application start-up and put it into a static variable somewhere. I suspect this won't meet your needs as typically the list you generate would be based on a specific query (I am guessing here).
All that being said, your concerns about memory usage and performance may be unwarranted. If you do some quick calculations about the memory usage of each Employee object, you may find it is a trivial amount. (Of course you won't be able to tell definatively how much memory it is using, but you may be able to hazard an educated guess). Remember also that things like Strings are "immutable" (never change) and are drawn from a "pool" of Strings. So, if you have two objects which contain the String "Java", they will actually both be using the same bit of memory.
Also, a word of warning: If you choose to maintain your "in memory" model, you may run into concurrency issues. Consider the situation where the initial query generates a list of Employees. The user traverses the list looking at the details of each employee. Meanwhile, another user is changing the details of an Employee on disk, but the first user hasn't looked at the details of this Employee from their list yet. Because the list the first user is viewing is in memory, it won't reflect any alterations made since it was generated. So when the first user views the details of the Employee that the second user altered on disk, they will see the "old" details for that Employee.
So, in summary the only two choices I can think of that are reasonable are:
1. Keep things the same but don't destroy the Map in the session so the first page always has it, and suffer the memory issues. (remembering the warning above)
2. Limit the scope of the data to the "request" only, and re-query every time. This will have poorer performance from a "response-time" perspective but avoids concurrency issues.
My recommendation:
If the list is "small" (sub 100 items), and you don't care about the risk of viewing "old" data, keep it in the Session. If the list is too big, perhaps you could look at only storing the first X number or records in the session and only displaying the first X number of records in the first JSP (like a search engine does)
If the list is big, and/or you DO care about viewing old data, maintain the persistence on disk. If you choose this option, performance can be enhanced by using connection pools, stored procedures etc.
At the end of the day, memory will only cause a performance issue if you "run out". Maybe the solution is to simply add more memory to the server?
Hope some of this helps.

Similar Messages

  • When links are clicked, they do not fully display the NEW page until the mouse is moved.I know it is a current bug, and appears in no other browsers that I know of.

    It was pointed out that my links do not function correctly on Firefox on a Windows platform. When links are clicked, they do not fully display the NEW page until the mouse is moved! I have now observed it for myself on my fathers PC running Windows XP on Firefox.My PC is on Windows7
    It is the 5 version of Firefox, so I know it is a current bug, and appears in no other browsers that I know of.

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    * Don't make any changes on the Safe mode start window.
    * https://support.mozilla.com/kb/Safe+Mode
    If it does work in Safe-mode then disable all extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    * Use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    * Close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")
    In Firefox 4+ you can use one of these to start in <u>[[Safe mode]]</u>:
    * Help > Restart with Add-ons Disabled
    * Hold down the Shift key while double clicking the Firefox desktop shortcut (Windows)
    * https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes

  • Close the session when closing the opendoc link

    HI,
    Environment: BOXIR3.1 SP3 FP 3.6
    When the user logging into infoview/CMC that time one session is creating , once logged off session also automatically closing. But when we using the open doc link, we dont have option to sign out the application. At that time we wanted to close the browser. But in CMC still we could see the users session in active. Could you please help us to kill the session when the browser is closed .
    is there any possible to kill such kind if session in BOXIr3.1
    Thanks
    N/A

    Hi,
    You can only kill sessions using the SDK and it's not recommended.
    Sessions should be automatically cleaned from the CMS after the timeout period. If it is not your case, follow the steps indicated in this KBA:
    https://service.sap.com/sap/support/notes/1286471
    Regards,
    Julian

  • I'm in Safari, is there a way to change the order when you right click a link? Just upgraded to Mavrick OS

    I'm in Safari, is there a way to change the order when you right click a link? Just upgraded to Mavrick OS

    You can do that with the Menu Editor extension - https://addons.mozilla.org/firefox/addon/menu-editor/
    This extension has not been updated by its author in a couple of years, but another developer has updated it for Firefox 4, you can get the updated version from http://netticat.ath.cx/MyAddons/MyAddons.htm#3rdpartyaddons

  • Adobe Photoshop: Lasso tool (Why do I get a triple image of the tool when I left click mouse?)

    Lasso tool (Why do I get a triple image of the tool when I left click mouse?)

    Crystal ball time...
    If it's the cursor you're talking about In Windows, try this:
    Right-click the desktop.
    Choose Personalize.
    Click the Display link.
    Change to a slightly different size.  For example, if you're at 150%, try using the Custom sizing options link and setting to 149% or 151%
    If you're seeing what Trevor is showing, without a delay, it's possible your left and right mouse buttons are swapped.
    -Noel

  • How to set the session using onClick event?

    Dear All,
    I have a link, which once the user click on it, I want to set the session.
    <a href="link.jsp" > Link </a>How to set the session? Where should I put <%session1.setAttribute ("test", "1234"); %>?
    Any idea?
    Thanks

    when u click on Link
    the control goes to link.jsp/.
    and in this page u can write the session related code.

  • Setting the border when JCombobox get focused

    Hello,
    Is it possible to set the border when the JCombobox get focused?
    In fact, I would like to hide the border at all, but remain the "setFocusable(true)"
    Thanks in advance.

    So why did you post your last three questions in the Swing forum, but then decide to post this "Swing related" question in the Java Programming forum?
    Is it possible to set the border when the JCombobox get focused?Try it!
    If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
    Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.

  • I cannot delete songs from my iphone via itunes, but can with my ipod and regular library. The option when I right-click isn't there ONLY with the iphone, any ideas how to get back this option?

    Can anyone help me get back the options when I right click with my iphone with itunes that drop down menu has oly 3 features and none is what I want or need?
    This happened since the last update.
    Geoff

    I am facing the same problem, please help us ...

  • Trouble setting the session state of a select item.

    Hi,
    I have a requirement whereby I need to change the session state of a select list item in my form without the need to submit. I am using Application Express 4.1.0.00.32. I thought this would be straight forward using a dynamic action or javascript and calling an on demand process for example.
    P1_MY_SELECT onchange="set_option();"
    function set_option() {
    var l_option=$f_SelectValue('P1_MY_SELECT');
    alert( 'My new value is ' + l_option );
    // ON DEMAND Set the new session state value
    var lRequest = new apex.ajax.ondemand
    ('SET_P1_MY_SELECT',function()
    {  /* start the return function */
    var l_s = p.readyState;
    if(l_s == 1||l_s == 2||l_s == 3)
    else if(l_s == 4)
    { gReturn = p.responseText;
         (gReturn)?json_SetItems(gReturn):null;
    else{return false;}
    /* end the return function */
    lRequest.ajax.addParam('x01', l_option );
    lRequest._get()
    My on demand application process
    DECLARE
    l_options varchar2(2000) := wwv_flow.g_x01;
    BEGIN
    APEX_UTIL.SET_SESSION_STATE('P1_MY_SELECT',l_options);
    apex_util.json_from_items('P1_MY_SELECT');
    END;
    Is there a better method to set the session state of my P1_MY_SELECT other than what I am doing as above or can you tell me why the session state of P1_MY_SELECT is not changed?
    Thanks.
    Edited by: 968358 on 01-Nov-2012 08:40

    if you are on 4.1 why don't you use a dynamic action instead of writing the code again?
    create a dynamic action like this
    Event: Change
    Source Type: Item
    Item: P1_MY_SELECT
    True Action:
    =========
    Action: Execute Plsql Code
    Plsql Code: null;
    Page Items to Submit: P1_MY_SELECT
    Page Items to Return: P1_MY_SELECT (this is optional)
    http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21674/advnc_dynamic_actions.htm#HTMDB27020

  • How to set the selectedIndex when dataProvider is an XML object in DropDownList?

    dataProvider was an XML object
    How to set the selectedIndex when dataProvider is an XML object in DropDownList?
    I do this:
    <s:DropDownList id="dropDownList" requireSelection="true" selectedIndex="2"
                    labelField="lastName" dataProvider="{employeeService.lastResult.employees.employee}"/>
    But always the first item is selected whatever the value of selectedIndex equals to.

    if i understand correctly, you want the selectedindex to be 2 when the DropDownList  displays.
    It might be the case that the dataprovider is being sought after it's already selected its index (as the dataprovider isn't already determined to begin with), so currently it's
         - setting the selected index to default
         - setting the selected index to 2 (your command)
         - getting the dataprovider
         - setting the selected index to default
    try writing a function to set the DropDownList's selected index after it's received the information, or even just attach it to the employeeService result handler.
    for quick testing sake you could just add
    <s:DropDownList id="dropDownList" requireSelection="true" updateComplete="dropDownList.selectedIndex = 2"
                    labelField="lastName" dataProvider="{employeeService.lastResult.employees.employee}"/>
    to see if my theory is correct.

  • Firefox 3.6 does not open onto my desktop from the dock when links in email or other files are opened. I have eMac with system 10.4.11 in English

    Firefox 3.6 does not open onto my desktop from the dock when links in email or other files are opened, use to. I have eMac with system 10.4.11 in English
    Thanks, Claude Combs
    [email protected]

    Firefox 3.6 does not open onto my desktop from the dock when links in email or other files are opened, use to. I have eMac with system 10.4.11 in English
    Thanks, Claude Combs
    [email protected]

  • Ever since I updated to Firefox 7.1, my computer won't go to the internet when I double-click the Mozillz Firefox icon, like it normally does; I have to restart my computer to be able to access the internet. Why?

    Ever since I updated to Firefox 7.1, my computer won't go to the internet when I double-click the Mozilla Firefox icon, like it normally does; I have to restart my computer to be able to access the internet. Why?

    There is a difference between remembering the name and password in the Password Manager and a "remember me" check box on a web page to log you in automatically.<br />
    The latter usually involves the creation of a special "remember me" cookie that is stored on your computer and that is send to the server.<br />
    If that "remember me" cookie is removed or gets corrupted or is not send to the server then the server won't remember you anymore and you need to sign in once again.<br />
    <br />
    * http://kb.mozillazine.org/Cookies
    * http://kb.mozillazine.org/Password_Manager
    So make sure that you keep the cookies from those sites via an allow exception and that you do not clear the cookies or site preferences via "Clear Recent History".

  • Can someone tell me why this is not setting the session variable?

    first page
    <?php
    // script1.php
    session_start();
    echo "<form action=\"script2.php\" method=\"post\"
    name=\"name1\">";
    echo "Your name: <input name=\"name\" type=\"text\"
    size=\"20\" value=\"\">  ";
    echo "<input name=\"submit\" type=\"submit\"
    value=\"Submit\">";
    echo "</form>";
    ?>
    second page
    <?php
    // script2.php
    session_start();
    echo('Hello, ' . $_SESSION['name1']);
    ?>

    jlw12689 wrote:
    > second page
    >
    > <?php
    > // script2.php
    > session_start();
    > echo('Hello, ' . $_SESSION['name1']);
    > ?>
    You need to set the session variable first.
    <?php
    session_start();
    if (isset($_POST['name1'])) $_SESSION['name1'] =
    $_POST['name1'];
    echo 'Hello, ' . $_SESSION['name1'];
    ?>
    By the way, using echo to create your form on page one is a
    complete
    waste of time. Just use an ordinary HTML form - a lot less
    typing, and a
    lot more efficient.
    David Powers
    Adobe Community Expert
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    http://foundationphp.com/

  • Is it possible to have Flash open the menu when you right click a link?

    I'm using sIFR 3 on a few of my websites. Personally I think it's a really cool and nice solution. I have had no issues with it so far except what I've recently discovered.
    When you right click on a link (or control click on a mac) it should have the normal menu you'd get if you clicked on a regular HTML link. Also when you hover over the link it doesn't display the status in the status bar (i.e. the URL the link will take you to if you click it).
    Anyways, I'm trying to come up with a workaround to this (personally I think the developers should have already thought of one but I guess not). That being said I'm wondering if Flash can do something like that. Is there a code I can put in the Actionscript to tell it to open up the browser menu when someone right clicks or control clicks a link?
    For some reason I'm thinking this isn't possible without JavaScript but I have had some people telling me in the current version of Flash it isn't possible at all. I'd be interested in hearing everyone else's opinion.
    To see what I'm talking about check out this website I'm building here... http://dev.thinktecmediagroup.com/fibre-federal/
    Notice that the top navigation (and side navigation) is all done using sIFR. IF you try and right click (or control click on Mac) on one of the links you'll see nothing happens.

    Probleme solved without having to change anything in the flash.
    The solution was to add a small part in the CSS in HTML
    html {
    overflow-x: hidden;
    overflow-y: auto;
    Solve probleme. All browser. VERY usefull to know !

  • HT1338 Can I set the MacBook Pro to make clicking sounds when I type?

    Is there a way to set the keyboard to make clicking sounds when typing?

    There is no settings in the System Preference to accomplish that.
    Exception.
    System Preference > Universal Access
    Slow Keys with use click key sounds.

Maybe you are looking for