Session Problems in Servlets

Hi i had one doubt in session (servlet)
I had deploy two application in tomcat with two different war files e.g., A.war and B.war.,
At one situation i am forward my application from A to B at the time i had store some values in session in A and Pass to B
My question is
Whether it is possible to  pass the session from A application to B application   how it is can u give solutions
Regards
Marimuthu

hi,
you have to make true for crossContext attribute
for ex
in your installtomcatdir/conf/server.xml
<Context path="/air" docBase="d:/air" debug="0"
                 reloadable="true" crossContext="true">

Similar Messages

  • Session problem in servlet??

    hello,
    i have made a simple shopping cart which goes through the
    following stage:
    1st stage:
    // Additions to the shopping cart
    HttpSession clientSession = request.getSession( true );
    ShoppingCart vBasket = (ShoppingCart)clientSession.getValue("thecart");
    if ( vBasket == null ){
    System.out.println("NO CART");
    vBasket = new ShoppingCart();
    clientSession.putValue("thecart", vBasket);
    System.out.println("MADE THE CART");
    vBasket.add(the_item);
    // at this stage, the items are being added to a hashtable
    2nd stage:
    HttpSession clientSession = request.getSession(false);
    System.out.println("GOT THE SESSION");
    ShoppingCart vBasket = (ShoppingCart)clientSession.getValue("thecart");
    if ( vBasket == null ){
    System.out.println("CART HASN'T BEEN MADE!!");
    throw new Exception();
    // At this stage, the object of the ShoppingCart class still has null value even if in the existing session the ShoppingCart has been made at stage 1. Any idea why this is happening??
    thanks
    Richard

    i believe that if u declare the writer before u get the session you may have problem like yours (happened to me). so make sure to get the session before instantiate your (response)writer.

  • Session problem in one out of two jsp

    Dear java guru's
    I have got jsp page A.jsp.User select few option and this jsp calls
    B.servlet this takes user input and pass to
    C.bean which returns vector to B.servlet
    This servlet put vector in session and dispatch to new jsp
    D.jsp which calls
    E.jsp in it for Image generation.
    This E.jsp retrieve vector from session and generate a image and reurn to D.jsp
    Now my problem is that session in B.servlet and D.jsp are same but a new session in created in E.jsp so image is null as it could get data from vector which is null.
    I put System.out.println(session.getId()) in each servlet and jsp so to get thier ID's.
    This is working fine in my system with Tomcat 3.2 but on web the new session is created for E.jsp
    I am calling E.jsp like this
    <img src=<%=response.encodeURL("/iscap/report/jspChart.jsp")%> alt="generation image" width="400" height="350" border="1">
    I am making page session=true in each jsp and also puttting request.getSession(false);
    but still E.jsp is getting new session.I tried eliminating each one and made all combination that could be possible but not effect.
    How Can I solve this problem on the web where I have to load this?
    Do I have to make setting in context .
    payal sharma

    Hi,
    If you have been using jspChart v 1.00 :
    As shown in the modified , attached PPT :
    I will be displaying a bar chart. The length of bar chart is obatined from Sybase database. This chart should be dynamically created depending on the value on
    the database and x -axis is exponential.
    This will be displayed on a HTML page.
    1. I want to know whether,the values can be obtained the values from Sybase database ?
    If so, what are the changes.
    2. can you tell me the steps to install and run the jspchart v 1.00 on Jrun or any server please.
    Any thing else, I need to install like SAX , JCLARK. I am getting errors in this. PL HELP.
    3. Is it possible to plot "Exponential values" in the Y-axis. like 0 - 100- 1000 - 10000 - 100000
    and the length of the Bar should automaticall be coloured till that Point as shown in the Power point attached.
    If not, any suggestions to use any other software.
    Thanks in advance.
    [email protected]

  • Session problem on clustered sun fire with SP6.1

    Hi All,
    I am having a problem with a webapplication on a clustered system.
    In the following I describe the current system setup.
    I will then describe the setup of the web application.
    Following this, I explain the trouble I'm having with sharing sessions in this environment.
    Finally, I pose the key question.
    SYSTEM SETUP:
    Our group has a clustered server setup. I believe the two machines are Sun Fire systems running Solaris 9. Let me know if you need more information concerning the HW.
    To manage the cluster, we use Sun Cluster software. Let me know if you need to know the version number. I do not have it handy. We just recently setup the system (in the past 6 months).
    Also, we have the newest Sun Web Server installed 6.1. We used the default installation. The only thing we changed was the dynamicreloadinterval variable from "-1" to "60".
    WEB APPLICATION:
    We have a fairly simple MVC web application setup, which works well on a single-server system. Essentially, the web application (1) asks for a certain input via a webform, (2) takes this input, and uses it to get information from a database, (3) puts this information into a httpsession attribute, (4) redirects the response to a JSP. The JSP gets the httpsession attribute (populated in step 3) and prints it out.
    So, HTML with form posts to Servlet, Servlet gets data from database and populates a session attribute, JSP gets that session attribute and prints it out.
    Between each transition from HTML, Servlet and JSP, the currently processing server may switch. I.e. the HTML may be served, for instance, by ClusterServer1, the Servlet may be handled, for instance, by ClusterServer2, and the JSP may be served at random by either.
    THE TROUBLE I'M HAVING
    Sometimes, my JSP is able to find the session attribute and print out whatever I put into the session during the Servlet step. However, sometimes, the JSP will print out "null" (the session attribute isn't available to the JSP).
    For the HTML and the JSP, I have the page print out what server it is being served from. Thus, I can tell that the HTML is served from, for instance, ClusterServer1 while JSP is served from, for instance, ClusterServer2. Sometimes, the same server serves both.
    KEY QUESTIONS:
    Why would this be happening?
    How can I have a session stick to the user and be shared across both servers?
    What other information would you need to provide an answer concerning this issue?
    I appreciate your efforts very much!
    Matthias Edrich
    dailysun

    Hi All,
    Hi Elving,
    I read through the documentation and have the following questions:
    (1) It seems that I can share sessions amongst both servers if I
    configure the web server to store sessions in a persistant manner such as in a file or in a database. Is this correct?
    (2) To enable this persistent storage of a session, I would need to change the Session Manager used. Is this correct?
    (3) If yes, I have the choice between the following managers. Please correct me if I have misunderstood the options.
    - PersistentManager: Instead of securing session information
    in memory, this manager saves session information within
    a file on the server in a directory, which I specify within
    sun-web.xml
    - IWSSessionManager: With this manager, I can store sessions
    in a defined database or file on the server.
    - MMapSessionManager: This manager also stores sessions in
    a file on the server
    (4) What is the difference between PersistentManager and
    MMapSessionManager if my web server is running in
    single-process mode?
    (5) If MMapSessionManager is a file-based manager, where do I
    specify to what directory the related file is stored to as I
    do in PersistentManager?
    (6) What are the advantages and disadvantages of
    Persistent/IWS/MMap managers?
    (7) In looking at SessionManagers, am I even barking up
    the right tree? It seems like these would help me share
    sessions across clustered servers.
    (8) Finally, I guess my plan of action would be the following:
    -> Identify what session manager to use
    -> Include a sun-web.xml file in /WEB-INF containing
    the manager-specific info
    -> Reload my web application
    -> done...
    Is this correct?
    Elving, I appreciate your help. Thanks!
    dailysun

  • Maintaining Sessions through Multiple Servlets and Contexts

    Hi,
    I have a webapplication that works like this:
    * User connects to a login servlet on HTTPS
    * Users information is authenticated on HTTPS
    * An object is stored in the session for other servlets to validate the users access
    * Authenticated users are forwarded to an HTTP page where the session is used to make sure they were granted access
    My problem is this....Since I create the session in an HTTPS context, when I am in the HTTP context, I am unable to access the session and constantly get NULL. Is there any way that I can access the session from an HTTP context?

    What you can do is, just login using HTTPS and switch over to HTTP
    and then store data in session.That is true, but what I want in the session is basically a flag on whether or not the user was granted access. I would much rather set all that up on the secure line, and then just access it from the unsecure ones...
    For example, you are creating session using the
    http://testdev:port/index.jsp page.
    If access the same page(with hostname)
    http://10.300.20.18:8080/index.jsp, you can't get the session even
    though both are same web server and same web application. Because the
    browser treats it different sessionI think if you use my above solution with the explicit passing of the jsessionid, you can move from one domain to another and still maintain session. Not positive on that though...

  • What is session tracking in servlets?

    Hi ,
    I'm studying servlets I don't have the clear idea about session tracking and Why and where we need to use it. Can any one say about this.....
    Thanks in advance,
    Maheshwaran Devaraj

    Well Mheshpmr session tracking in servlets is very important...There are a number of problems that arise from the fact that HTTP is a "stateless" protocol. In particular, when you are doing on-line shopping, it is a real annoyance that the Web server can't easily remember previous transactions. This makes applications like shopping carts very problematic: when you add an entry to your cart, how does the server know what's already in your cart? Even if servers did retain contextual information, you'd still have problems with e-commerce. When you move from the page where you specify what you want to buy (hosted on the regular Web server) to the page that takes your credit card number and shipping address (hosted on the secure server that uses SSL), now let me tell you, how does the server remember what you were buying?
    Well There are three typical solutions to this problem.
    1. Cookies. You can use HTTP cookies to store information about a shopping session, and each subsequent connection can look up the current session and then extract information about that session from some location on the server machine. This is an excellent alternative, and is the most widely used approach. However, even though servlets have a high-level and easy-to-use interface to cookies, there are still a number of relatively tedious details that need to be handled:
    * Extracting the cookie that stores the session identifier from the other cookies (there may be many, after all),
    * Setting an appropriate expiration time for the cookie (sessions interrupted by 24 hours probably should be reset), and
    * Associating information on the server with the session identifier (there may be far too much information to actually store it in the cookie, plus sensitive data like credit card numbers should never go in cookies).
    2. URL Rewriting. You can append some extra data on the end of each URL that identifies the session, and the server can associate that session identifier with data it has stored about that session. This is also an excellent solution, and even has the advantage that it works with browsers that don't support cookies or where the user has disabled cookies. However, it has most of the same problems as cookies, namely that the server-side program has a lot of straightforward but tedious processing to do. In addition, you have to be very careful that every URL returned to the user (even via indirect means like Location fields in server redirects) has the extra information appended. And, if the user leaves the session and comes back via a bookmark or link, the session information can be lost.
    3. Hidden form fields. HTML forms have an entry that looks like the following: <INPUT TYPE="HIDDEN" NAME="session" VALUE="...">. This means that, when the form is submitted, the specified name and value are included in the GET or POST data. This can be used to store information about the session. However, it has the major disadvantage that it only works if every page is dynamically generated, since the whole point is that each session has a unique identifier.
    Servlets provide an outstanding technical solution: the HttpSession API. This is a high-level interface built on top of cookies or URL-rewriting. In fact, on many servers, they use cookies if the browser supports them, but automatically revert to URL-rewriting when cookies are unsupported or explicitly disabled. But the servlet author doesn't need to bother with many of the details, doesn't have to explicitly manipulate cookies or information appended to the URL, and is automatically given a convenient place to store data that is associated with each session.

  • Java Session problem while sending mail(using javamail) using Pl/SQL

    Hello ...
    i am using Java stored procedure to send mail. but i'm getting java session problem. means only once i can execute that procedure
    pls any help.

    props.put("smtp.gmail.com",host);I doubt javamail recognizes the 'smtp.gmail.com' property. I think it expects 'mail.host'. Of course since it cannot find a specified howt it assumes by default localhost
    Please format your code when you post the next time, there is a nice 'code' button above the post area.
    Mike

  • Problem in Servlet Compilation & Deployment

    Hi Friends,
    I have problem regarding Servlet Compilation & Deployment.
    At the time of compilation gives error message "import javax.servlet.* is not a recognize package.
    My J2ee Server gives FATAL Error it says it should be work on JDK1.2 or later.
    My JDK is :-j2sdk1.4.2_04
    MY J2EE Server is:-j2sdkee1.2.1
    My Servlet Runner is:-JSDK2.0
    My Java Enviorment is:- Version 1.5.0 (build 1.5.0_04-b05)
    Path setting is:-
    Class Path=C:\j2sdk1.4.2_04\lib;C:\j2sdkee1.2.1\lib\j2ee.jar;C:\JSDK2.0\lib
    CommonProgramFiles=C:\Program Files\Common Files
    COMPUTERNAME=DCL-04
    ComSpec=C:\WINNT\system32\cmd.exe
    Please help me and give the desired result as soon as you all can
    Your's Harish
    Thanks

    At the time of compilation gives error message "import javax.servlet.* is not a recognize package.You have to include servlet.jar or j2ee.jar in the classpath when compiling.
    My JDK is :-j2sdk1.4.2_04
    My Java Enviorment is:- Version 1.5.0 (build 1.5.0_04-b05)Why are the versions of your JDK and Java runtime environment different? Why are you not using Java 5 to compile and run everything?
    Class Path=C:\j2sdk1.4.2_04\lib;C:\j2sdkee1.2.1\lib\j2ee.jar;C:\JSDK2.0\libIf this is an environment variable, it should be "classpath", not "Class Path" with a space in between.

  • Session problem in jsp application

    I face a session problem. I setting everything in a session and when pass back to a main page, the value is not display in the screen. But after refresh the value will display in the screen and this kind of problem only come out very few time and i dun knw how to solve this...
    Anyone here can give me some idea and suggestion or the way to solve this kind of problem!!!

    define "2 different clients"
    1) You have 2 different PCs and it's using the same session ID for both? I doubt this. I think the server is advanced enough not to use give a session ID that's already been created.
    2) You have 1 PC and are using IE or Netscape and using File > New Window to open a new window and connect again. This you can't fix without using only URL rewriting to manage session, because the different windows will share the same session cookies.

  • Implementing session handling in servlet controller

    how to implementing session handling in servlet controller.
    instead of writing isNew() in every jsp page i wanted to write in my central controller ,where each request is passing through controller. can any body give me the solution

    i tried it it is failed because first time the request is coming to the controller.it checks for new since of it is a first request it is forwarded to the login page.how to avoid or skip the condition checking when the request is first time.

  • Maintain session when calling servlet from form in a JSP

    I have the following set up:
    index.jsp calls login servlet from the action tag in a form.
    Login servlet handles the login, stores the user info and db connection in the session and uses forward(req,res) to call another jsp.
    That jsp has a form where user enters search info and in that form's action tag there is a search servlet. In the search servlet I am unable to access the session.
    Is there any way to pass the session to the servlet from that jsp using a form/action?

    I've read elsewhere that if you go from a jsp to a servlet that the >request object is cleared of any attributes from the previous request.which is correct. But arent we speaking about session object here? A request object is valid for a request - ie the phase from where the server receieves a hit for a resource upto the point it sends the output for that request.
    A session spans multiple requests.
    it doesn't retrieve the session info and gives me a null pointer >exception when I try to use the connection object stored in the session.Bad bad bad . Why do you store Connection objects in session? Create them when necessary or use a connection pool. Do you for example clean up the connections when the session expires. What if its a 30 minute session and the user hits every say 15 minutes with a request. Why do you need to hold on to the Connection in the intervening interval when the user's session is inactive?
    gives me a null pointer exception when I try to use the connection object stored in the session.which means that the Connection object is null - not the session object.
    That last line is where I get the null pointer exception. And that is
    Statement stmt = con.createStatement();?
    Same answer as above.
    If the session object was null,
    userSession.getAttribute("connection");would have thrown a NPE.
    ram.

  • Image reading problem in servlet

    Image reading problem in servlet
    I am reading an image in servlet and writing it to ServletOutputStream
    The following code works fine unless I change the size of the byte array (for increasing download speed) from 8 to something like 128 or any other higher value
    If I change the value of byte array size the image does not get downloaded properly, I mean the quality of the image changes, it does not looks like the original imageURL url = new URL("http://www.mysite.com/images/img1.jpg");
    URLConnection con = url.openConnection();
    con.setUseCaches(false);
    BufferedInputStream in = new BufferedInputStream(con.getInputStream());
    BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
    byte b[] = new byte[8];
    while(in.read(b) != -1)
         out.write(b);
         out.flush();               
    out.close();
    in.close();what do I change
    byte array size
    or use the constructor of BufferedInputStream with 2 parameter
    or use the constructor of BufferedOutputStream with 2 parameter
    or use flush outside while loop or what else

    Change your while loop to:
    int count;
    while((count = in.read(b)) != -1)
         out.write(b, 0, count);
         out.flush();               
    }The penultimate time read is called, it may not fill the entire byte array. You only want to write out however much was read into the array.
    For better performance, you should move the flush() outside of the loop too. BufferedOutputStream will flush automatically when its internal buffer is full.

  • Can you tell me How to loading sessions.xml in servlet

    Can you tell me How to loading sessions.xml in servlet

    Getting a session in a servlet is no different than in any other environment except that you need to be careful which classloader you pass to the SessionManager and correctly configure what to do if your application is reloaded. If you use the oracle.toplink.util.SessionFactory introduced in 10.1.3.1 you don't have to worry about these details--it uses the correct settings. The SessionFactory greatly simplifies the code required to get a session or unit of work. It's well documented in the SessionFactory javadoc.
    If you do use SessionFactory beware there is a bug when running in a JTA environment and there's no transaction started. Doug posted a work around in his blog[1].
    --Shaun
    [1] http://www.jroller.com/page/djclarke/20060412

  • Session Cookie in Servlet

    Hi all
    I have a issue please answer me.
    If users disabled cookies.( other than session cookies)
    how i should dynamically switch session cookies.
    and how i can generate session cookies in servlet?
    thanks
    yashvant

    If the user has cookies disabled (session, since persistent ones are rarely used for maintaining session state with a browser), then most containers will attempt 'url-rewriting' and insert the session uid there (in the URL). That should work even if cookies are disabled. In order to access a session, you simply call HttpServletRequest#getSession(). If no session exists, one will be created, else the existing one will be retrieved. The J2EE container will send either a cookie in the response or re-write the URL. You don't have to do anything special.
    - Saish

  • Configuration of sessions for deployed servlet, jsp, wdp

    Hello,
    I wonder how to configure session for a specific servlet. As there are several locations where to deal with session management.
    I have found the Security Provider->SessionExpirationPeriod property which is fixed to ~27 hours, this is a general parameter for all security providers.
    I need to do it per application, I have then tried to set the session in the servlet descriptor it is not taken into account.
         <session-config>
              <session-timeout>10000</session-timeout>
         </session-config>
    The security provider of the servlet is set to SAML authentication.
    Thanks for your input on this topic,
    Tanguy Mezzano

    Finally, it was that parameter.

Maybe you are looking for

  • How do I transfer Photoshop to my new laptop without install CD?

    My laptop is ancient and about to die. I have a new one and I want to transfer Photoshop onto my new one. I know I can deactivate Photoshop on my old laptop but how do I get it on my new one? I can't remember 100% but I'm sure I installed it via down

  • What is the benefit in using OID for names resolution?

    I have been wondering about this for awhile. I have been working on getting this to work in Iplanet along with Pat Lehane ([email protected]), and it works now. What are the benefits in using OID for names resolution when you can just use the static

  • How to make more hard disc space available

    Working in iMovie, I ran out of hard disk space so I cleared Trash and moved everything that was not essential for the task in hand onto a memory stick, including most applications such as iWork. However, no matter what I removed or cleared I was una

  • Facetime verification email not arrivinh

    I am sitting here trying to get Facetime going for my Mother so she can video chat with her grandchildren.  Thusfar all has gone well enough - installed Facetime, got her Apple ID setup, and entered in to Facetime.  However, we appear to be stuck at

  • ICal is not showing some past events since I upgraded to Lion.

    iCal is not showing some past events since I upgraded to Lion. I can find the past events in mail but if I click and open them, they are not showing up on the calendar. Advice? I am trying to recreate my schedule from past meetings.