URGENT! Share session object in JSP and JServlet

Dear all,
I am new to OAS. I am now trying OAS by build a simple Shopping Cart application.
Currently, I use JSP to build user interface and Servlet to build bussiness logic. So I use JSP cartage and JServlet cartage to build the application.
However, I find that the "session object" I create in the JSP cannot be access from Servlet cartage.
Is anyone can help me to solve this problem. ( Is this implementation framework works in OAS ? )

>
I am short describing the problem again,
IN JSP, MY CODE IS LIKE THIS:
HttpSession oSession=request.getSession(true);
oSession.setAttribute("batchHash",reqRows);
IN SERVLET, MY CODE IS LIKE THIS:
HttpSession oSession=req.getSession(true);
tblSession = (Hashtable)
oSession.getAttribute("batchHash");
System.out.println("IsNew ="+oSession.isNew());
System.out.println("Object="+prmSSO);
If I deploy this in TOMCAT, my output is like this:
IsNew =false
Object=Hashtable@982fc1
If I deploy this in WEBLOGIC 6.1, my output is like
this:
IsNew =true
Object=null
Why is this?
Why the "oSession.isNew()" returns "false" in tomcat
and "true" in weblogic ?
Please help....Your only problem is using
HttpSession oSession=req.getSession(true);instead of
HttpSession oSession=req.getSession(false);in your servlet! getSession(true) - forces to allocate new session,
so it's absolutely clear why your Hashtable is absent in
a newly created session!!
Paul

Similar Messages

  • How to share session object between multiple WAR's

    I am Using servlet 2.3 & websphere 5.1 application server. I am using multiple war applications in my ear and i am able to share context-attributes & session attributes between wars. Can any one guide me how i can share session object?
    I am getting session -time out in first war even though i am doing some operation's in second war. I want to maintian the same session, even in my second war which was created in my first war.
    Can any one help me. Thanks in advance.

    Hi LNL,
    Can you explain more on singleton solution as you said....
    For session attributes & context attributes i am using persistent storage to retrive them in multiple wars. My problem is how should i use "session object" in my second war which was created in my first war.

  • Urgent: problem with sharing HttpSession  object between Jsp and servlets.

    Hi,
              We are using weblogic 6.0 sp2.
              I m setting a particular object in session in a servlet using
              session.setAttribute() but when i try to retrieve that object using
              session.getAttribute() in a jsp page the value of that object is null. Is
              there any way to configure HttpSession in weblogic so that jsps and servlet
              can share the same session? Or any workaround for this problem.
              Any help in this regard is appreciated.
              Thanks
              -Shree
              

    Just a guess, but it sounds like you have cookies turned off and are not
              using encodeURL. Try enabling cookies and see if that solves the problem.
              Also, it is generally good practice to use encodeURL to protect yourself
              from users who disable session cookies.
              Here's how we use encodeURL in our Servlets:
              gotoPage("/jsp/someJSP.jsp");
              private void gotoPage( String address,
              HttpServletRequest request,
              HttpServletResponse response )
              throws ServletException, IOException
              RequestDispatcher dispatcher =
              etServletContext().getRequestDispatcher( response.encodeURL( address ));
              dispatcher.forward( request, response );
              "Shree Unde" <[email protected]> wrote in message
              news:[email protected]..
              > Hi,
              > We are using weblogic 6.0 sp2.
              > I m setting a particular object in session in a servlet using
              > session.setAttribute() but when i try to retrieve that object using
              > session.getAttribute() in a jsp page the value of that object is null. Is
              > there any way to configure HttpSession in weblogic so that jsps and
              servlet
              > can share the same session? Or any workaround for this problem.
              > Any help in this regard is appreciated.
              > Thanks
              > -Shree
              >
              >
              

  • How the hell does a person share session data between JSP page and a Servle

    1. How the hell does one share session data between a servlet and a JSP page without using a bean but rather using a normal string variable.
    2. When using session scope to access a bean the application complains about not finding the bean on the specified scope, however when I use an application scope the save the same bean, the application does find it.
    Please help!!!!!!!
    SERVLET:
    HttpSession session = request.getSession(true);
    ServletContext servletContext = session.getServletContext();
    customerID = result.getString("CustomerID");
    userName = result.getString("UserName");
    session.setAttribute("UserName",userName);
    session.setAttribute("CustomerID",customerID);
    System.out.println("Customer UserName = " + session.getAttribute("UserName"));
    response.sendRedirect("/economics/subscriptions/default.jsp");
    JSP PAGE:
    <?xml version="1.0" encoding="UTF-8"?>
    <jsp:root xmlns:jsp=http://java.sun.com/JSP/Page mlns:c="http://java.sun.com/jsp/jstl/core" xmlns:sql="http://java.sun.com/jsp/jstl/sql" version="2.0">
    <jsp:directive.page isThreadSafe="true" session="true" contentType="text/xml"/><jsp:output omit-xml-declaration="false"/><jsp:scriptlet>response.addHeader("x-xslt-nocache", "true");</jsp:scriptlet><pml>
    <page type="web" search="y">
         <pageName>Commercial Banking</pageName>
         <jsp:directive.include file="/economics/header.inc"/>
         <jsp:directive.include file="/login.inc"/>
         <jsp:directive.include file="/economics/leftMenu.inc"/>
         <!--<jsp:useBean id="UserName" type="java.lang.String" scope="session" />-->
         <content>
         <searchSum>Commercial - Main Content</searchSum>
         Value = <c:out value="${request.session.getAttribute("UserName")}"/>
         </content>
         <jsp:directive.include file="/economics/rightNav.inc"/>
         <jsp:directive.include file="/footer.inc"/>
    </page></pml></jsp:root>

    For a start, just "session" instead of "request.session" would work better. But why did you post this here and not in the JSP forum? Doesn't seem to have anything to do with Java programming.

  • How to use session object in jsp

    hi all
    marry christmas
    can anyone plz tell me how to use session obect in jsp
    rachna
    Message was edited by:
    rachna_arora82

    hi rachna,
    JSP has a default(implicit) session object...... use the getSession(true) method on the session object and then going u can either get or set attributes depending on the requirement
    That was in general and now with the issue u have got..... what u can do is that the u can create session for every user who logs in and when he/she tries to login again then u can probably check for the existing session object in the JSP and perform the logic as required..... any clarifications plzzzzzzz let me know
    Thanks n Regards
    Naveen M
    Message was edited by:
    Novice_inJAVA
    Message was edited by:
    Novice_inJAVA

  • How to validate a session object in jsp?

    Hi All,
    i am facing a problem.The problem is how to validate the session object object in jsp.I have written a java script by using a defined function as setInterval and has given 5 mintues if the user is idle and will show a pop up menu before time out the session but in case of page active still this pop up menu is coming. The java script as follows.
    function SetTimer(){
         //How long before timeout (should be a few minutes before your server's timeout
         //set timer to call function to confirm update
         if(timeoutMinutes)
         timerObj = setInterval("ConfirmUpdate()",60000);
    function clearTimerFn(){
              timerCount = 0;
              clearInterval(timerObj);
              //timerObj = setInterval("ConfirmUpdate()",60000);
    function ConfirmUpdate(){
         //Ask them to extend
         if(confirm("Your session is about to expire. Press 'OK' to renew your session.")){
              //load server side page if ok
              var url = "ajaxSessionchecker.do?sessionvalidate=sessionvalid";
              LoadXMLDoc(url);
    And in jsp i am calling this js function as
    <%session=request.getSession(false);
              if(session.getLastAccessedTime()==60000){ %>
              <script type="text/JavaScript">
         clearTimerFn();
    </script>
    <%}else{
    session.setMaxInactiveInterval(-1000);} %>
    could you pls help me out?

    The reason for doing this is when ever i come to this user.jsp from account.jsp with a different account number this user.jsp is not refreshed and i still
    see the same old user.jsp for the previous account that i naviated before. Also please let me know if there is any other approach to acheive this taskDoes refreshing the page by pushing F5 solve the problem?
    If so, then the browser is caching the page, despite your attempts to stop it.

  • How to track the same session using both jsp and servlets

    Hello, guys:
    "how to use jsp and servlet to track the same session",
    it seems to me my logoff.jsp never realize the session I established in my servlets.
    Here is how I set my session in my servlets:
    "     HttpSession session = req.getSession(true);
    session.setAttribute("userid",suserid);"
    Here is how I invalidate my session in my logoff.jsp
    " <%@ page language= "java" %>
    <%@ page import="javax.servlet.http.HttpSession" %>
    <%@ page session="false"%>
    Our Session id is : <%= session.getId() %>
    <% session.removeAttribute("userid");
    session.invalidate();
    %>
    Our Session id is : <%= session.getId() %>"
    but when I try to logoff using the logoff.jsp
    I always get following error message.
    "/home/jiao/jsp_webserver/tomcat/work/Standalone/localhost/syllabus/htmls/logoff_jsp.java:50: cannot resolve symbol
    symbol : variable session
    location: class org.apache.jsp.logoff_jsp
    out.print( session.getId() );"
    T.I.A.
    [Edited by: jiveadmin on Jun 18, 2003 10:32 AM]
    [Edited by: jiveadmin on Jun 18, 2003 10:33 AM]

    So,
    <%@ page session="false"%>
    That means the jsp never instantiates the build in session object.
    <%@ page session="true"%>
    means jsp will instantiates a session object if there are no existing ones
    how about I just delete the line,
    does that mean the jsp will find the existing session object for me?
    So I can do something like
    Our Session id is : <%= session.getId() %>
    <% session.removeAttribute("userid");
    session.invalidate();
    %>
    directly.
    T.I.A.

  • Question about app design - database + session object in JSP

    hi all
    i am studying this application built mostly with servlets and JSPs, and there are several questions i want to ask your guys' opinions about it.
    first of all, i noticed that the application hits database to get/save data very frequently. from one page to another it would save data collected from user to the DB, and retrieve data from DB to display on the next page. it does this a lot. would this decrease the overall performance of the application, i mean a DB hit requires network traffic overhead, wouldn't it be better if all data collected from user are stored in a session object temporarily, and all the data that are displayed on those pages retrieved at the start time? and do one save process in the end. it uses Oracle DB if it makes any difference. should we try to avoid db hit as much as possible?
    my next question is that is it good approach to keep information in session object? even if there is a lot of data to keep?
    another question is the db connection. in a pooled environment - weblogic server, we would use JNDI in the code to get connection from the pool, we use it and close it. when we close a connection with close() method, what really happens? does this connection gets return to the pool or it is being destroyed completely.
    i know this is a lot to ask, i appreciate your help very much. looking forward to seeing some feedback.

    No, I don't have tables of values. I have a java 1.5 enumeration, like for instance:
    public enum VelocityConvention {
       RELATIVISTIC,
       REDSHIFT;
    }and a class Velocity that contains a convention and a value like so:
    public class Velocity {
       public VelocityConvention getConvention() {...}
       public double getValue() {...}
       public void set(VelocityConvention conv, double value) {...}
    }When I persist the Velocity class to the database, I want a field called convention that holds the appropriate value of the enumeration. That much is done how I explained before.
    I want to have a selectOneMenu for setting the convention. Via trial and error, I found that MyFaces wasn't able to automatically convert from a string back to a proper VelocityConvention enum constant. It can, of course, convert from the enum to a string because it just calls toString(). But I need both directions for any UIInput element I use, be it a selectOne, or just a straight inputText.

  • Passing session data between jsp and servlet

    I have a servlet that I pass data to my jsp.
    I do a session.setAtrribute in the servlet. No problem.
    I get the data no problem in the jsp that I call.
    How do I pass this same data to the another servlet?
    I basically have an array of values that I already have in the existing jsp that has been set in session.
    When I call the secondary servlet, I don't have anything in this session variable related to my array.
    Prior to posting to my next servlet, do I need to do another setAttribute inside the jsp to get the data passed to the servlet?
    Thanks.

    Two different things. The encoding adds this to the URL (after the page, before the query string
    ;jsessionid=ABC123 but only if the user isn't using cookies.
    So in your example, you would do this (maybe):
    <%
      String url = response.encodeURL("Servlet");
    %>
      <form name="form1" method="post" action="<%= url %>?cmd=pay"> ... Or some modification.
    So the difference between encodeing and using a post is that
    1) encoding adds the jsessionid to the url string if necessary. It does nothing else
    2) POSTing will send a request to the provided URL via the POST method, including the inputs of the form as parameters to the URL.
    They really don't interact with each other. It is like asking what is the difference between the Color Orange and thr Size Big? They can both be applied to the same thing, or not... and have no real relation to each other.

  • How can we share session information between browser and WebView

    Hi
    I have a web application which launches a instance of JavaFX web view on a click of a button. My issue is that when i launch this web view it creates a  new session of its own ,how can you transfer the session information of the parent (browser) to the web view.
    One of the solution i found was to add the JSESSION_ID cookie into the default(System-wide) cookie handler so it would override the existing cookie within the WebView cookiehandler.
    http headers - Setting a cookie using JavaFX&amp;#39;s WebEngine/WebView - Stack Overflow
    Are there any other solution for sharing session information between the web view instance and browser that launches it ?

    O.K. then, is it at least possible to access a wwsto_api_session
    from Java in the following way?
    Calling PL/SQL from Java
    JDBC and SQLJ allow you to call PL/SQL stored functions and
    procedures. For example, suppose you want to call the following
    stored function, which returns
    the balance of a specified bank account:
    FUNCTION balance (acct_id NUMBER) RETURN NUMBER IS
    acct_bal NUMBER;
    BEGIN
    SELECT bal INTO acct_bal FROM accts
    WHERE acct_no = acct_id;
    RETURN acct_bal;
    END;
    From a JDBC program, your call to the function balance might look
    like this:
    CallableStatement cstmt = conn.prepareCall("{? = CALL balance(?)}");
    cstmt.registerOutParameter(1, Types.FLOAT);
    cstmt.setInt(2, acctNo);
    cstmt.executeUpdate();
    float acctBal = cstmt.getFloat(1);

  • Need help in jsp and struts projects

    hi
    i am using jsp and struts framework.
    in that i am putting values in session in one jsp and getting
    values in other jsp.i am having doud with how many values i will put in sessions and it will give any difficulty while running in servers.and i want to know any other equivalent way is there for sessions.

    hi
    i am using jsp and struts framework.
    in that i am putting values in session in one jsp
    jsp and getting
    values in other jsp.i am having doud with how many
    ny values i will put in sessions and it will give any
    difficulty while running in servers.and i want to
    know any other equivalent way is there for sessions.do u want all those vales at the same time? if not then u might use session.removeAttribute() method for trashing out the not needed objects.
    there are many ways of session handling.... passing as request param, also using hidden fields, else th URL rewritting...
    but all these are not efficient to be passed along if too many pages are using the same session objects. i believe u can also try passing it into an XML file and parse it out whenever needed. but i dont think thats feasible enough.
    hope it helps.

  • How to communicate between Flex and JSP and show the result in an Iframe

    Hi all
    I am trying to send some data from flex to one HTTPService and trying to show the same response jsp in an Iframe. But unfortunately i am unable to get the responce Jsp's url to set as a source for iframe.
    let me explain you clearly...I have a mxml where i am having a text box and a button in the left panel and in the right panel i am having an Iframe to display jsp. So once user enters some value in the text box and clicks button then HTTPservice's send method will be called with text box's content as an arguement. So i can fetch that value from request object in jsp and display the value in jsp. So the problem here is i want display that result jsp in my Iframe. I know that , we need that result jsp URL to display in Iframe . But as i am sending POST request to HTTPservice, i am not able to get the result jsp's URL in flex side.
    So i need help desperately from great minds.So anyone of you can give me some suggestions!!!!
    Regards

    Hi all can some one please give a solution ...Any suggestions would be greatly appreciated

  • Can a Servlet be used for Storing Objects with both JSP and JSF used on it?

    Hi,
    Pages I have:
    SearchEmployee.jsp
    This page has a search engine that search out the Employee. This Employee Object will be stored inside a Servlet(controller) for future references by other pages. I used JSP, html tags for forms, and request.getParameter() to built this search engine.
    Problem:
    I have a JSF Form that wants to DISPLAY the employee which I have found in my Search Engine. How can I get the JSF's value="#{Controller.employeeObj.name}" to get the value from the object?
    This seems logical as my JSF form is just retrieving the stored object in the Controller. I currently cant seem to output it

    The servlet shouldn't be used to store ANY data, let alone data to be accessed by other sevlets. Put the object into the Session object.

  • Vector and session object...

    Hi, I have a JSP that retrieves a resultset with 3000+ rows. I use that resultset to create a summary page of grouped data, so the resulting page is only a few lines. Each group is a link that can be double clicked to call a JSP that will display the detail line items.
    From a developers viewpoint, this is how I'm doing it: On the first JSP, as I scan through the resultset creating the summary line items I add the detail data to a vector. After I'm done processing the resultset I add the vector to the session object. When the hyperlink on the first JSP is activated I call a second JSP that retreives the vector from the session object and display the results.
    Is that a good idea or a bad idea? It seems to work ok, but I'm thinking it might be alot of data to be storing on a session object especially when you consider the number of users that could be on. Is there a way to compress the vector when I add it to the session object? Is there a better way to do this? Unfortunately, I can't re-retrieve the data because the SQL takes too long. Thanks!

    Sure you could compress it... you could use the classes in java.util.zip, and use an ObjectOutputStream plus a ZipOutputStream plus a ByteArrayOutputStream (I think), using zip compression to convert your Vector into an array of bytes, and then do the reverse when you needed the data uncompressed. Chances are that would compress your data by about 80 or 90%.
    Here you would be making the classic tradeoff between memory usage and processing time; I wouldn't do this compression thing until it was clear that it was necessary, though.

  • Please help me-it's urgent,maintaining session and security using cookies.

    hi folks,
    i presently developing a web site for an engineering colleege ,i am facing prob in maintaining the session using cookies,and destroying a cookie and keeping security to the user,There are four links on my webpage ,including a logout link,when i click the other links other than the logout,it works perfectly,and when i click the logout link,i am not able to disable the cookie and still able to visit previous pages by clicking the back button.please give a suggestion as such to disable the cokie and maintain the security for my web site.
    Thank u....

    Try out this login if it helps you.
    Create a bean that stores some String value. Then make a object of this bean using the useBean tag with session scope when a user logs in. Store the name of the user in the bean and also set the same name value in the Session object. Then on every JSP page compare the value set in the session object with the bean variable (which will be having a session scope). If the value match, then the JSP page output must be displayed to the user. Then on the logout link, invalidate the session object using the invalidate() method of the session class. As a result now when you will try to navigate back to the old JSP page, null will be returned to you when you will try to retrive the name value from the session object. And since this null will not match with the value in the bean, you should not proceed further with generating the output. Hope this help
    Nirav ([email protected])

Maybe you are looking for