Session handling

dsavitsk dsavitsk at e-coli.net
Mon Sep 23 13:11:05 EDT 2002


"Andreas Ulbrich" <andreas.ulbrich at gmx.net> wrote in message
news:amn7dp$6cn$1 at mamenchi.zrz.TU-Berlin.DE...
> beachboy wrote:
> > Hi!
> > Please can anyone help me.
> > My problem:
> > I'm trying to program a web application with python. This tool has to
> > provide diffrent languages. The user has to choose the language at the
> > beginning. So i have to save the information which language the user
> > chooses. I think this is a perfect example for using sessions.
> > The only problem is I've got no idea how to realise this in python.
> > Please help me as soon as you can because I have to solve this problem
> > very quickly.
> >
> > hoping to hear from you soon
> > beachboy
>
> Whenever I need to write a web-application I do use jython and write
> servlets. This combines the power of Servlet/JSP with the worlds best
> programming language.
>
> a jython servlet would look like this:
>
> from javax.servlet.http import HttpServlet
>
> class MyServlet(HttpServlet) :
>
> def doGet(self, request, response) :
>
> session = request.getSession(1)
> lang = session.getAttribute('language')
> if not lang :
> # initialise the session (i.e. choose language)
>
> # produce output suitable to lang
> if lang == 'DE' :
> print >> res.writer, "Hallo Welt!"
> else :
> print >> res.writer, "Hello World!"
>
> There are other solutions. I believe that Zope offers session-management
> too.

If the only state that needs to be maintained is a language variable, this
seems like a lot of work when a cookie will work fine.

-d






More information about the Python-list mailing list