Passing data between servlets


Web tier: servlets, JSP, Web frameworks: Passing data between servlets

  1. Passing data between servlets (7 messages)

    I'm working on a simple web based inteface for administrating a MySQL server. The user should be able to log in (be verified by the SQL) and then be able to view, edit and delete rows in a table.

    Is the best approach to make different servlets for the different tasks (login, view table, edit table etc.) and passing the information through sessions or is it best to have one servlet doing it all?

    If a have a couple of servlets (which seems most reasonable) do I have to configure my servlet engine (Tomcat) in any way to make my servlets be able to use sessions together?



    Threaded Messages (7)

  2. Passing data between servlets[ Go to top ]

    u can have one servlet as an entry point
    and different biz object doing the logic 4 u.
    that data will b save in the session object
  3. Passing data between servlets[ Go to top ]

    So, if I make one servlet for verifying the user against a SQL that servlet can save the login name in a session and the other servlets can then check wheter an user is logged in or not?

    Will the session keep the state between all my servlets that run in the same servlet container (and even between servlet containers)?


  4. Passing data between servlets[ Go to top ]

    Yes it will.
  5. Passing data between servlets[ Go to top ]

    I havn't got it to work. If I use "HttpSession activeSession = req.getSession(true);" and then "activeSession.setAttribute("login", login);" to store the String "login" into "login" in the Session. So far everything works, but if I try to access the login String from another servlet it just returns null. Seems like I have to speak gentle with the ServletContext or something like that. Does anybody have an idea?

    The concrete problem is that I want a String to be stored in a Session that's not specific for a servlet so it can be read from different servlets.

    Thanks again!

  6. Passing data between servlets[ Go to top ]

    What server are you using? I remember having a similar problem using Tomcat 3.2 within VisualAge.

  7. Passing data between servlets[ Go to top ]

    I'm using Tomcat 3.2 under Mac OS X (BSD) and all the servlets are in the same context but I guess I have to do something else then just using the getSession method.

    Isn't there anybody out there succeding with using more then one servlet and still using sessions?

  8. Passing data between servlets[ Go to top ]


    It works. If you were here at my PC I would show you with Tomcat 4.0.

    Maybe you are resetting the session or something like that. Start from scratch with a very simple example - two servlets and some session data. Keep it simple so that you can isolate any possible errors.

    Believe me, it works as advertised.

    Why don't you upgrade to Tomcat 4.0 while you're at it? Like I said, I have had quircky results with Tomcat 3.2.