X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 05D9311F6056 for ; Fri, 28 Apr 2006 03:11:19 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 82344-08 for ; Fri, 28 Apr 2006 03:11:06 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web54215.mail.yahoo.com (web54215.mail.yahoo.com [206.190.39.48]) by postgresql.org (Postfix) with SMTP id D3D6911F6002 for ; Fri, 28 Apr 2006 03:11:05 -0300 (ADT) Received: (qmail 37425 invoked by uid 60001); 28 Apr 2006 06:11:05 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=2ah4C+jcWHAHRTR01qlbalVe4KSj5PxLUj3E0vWYa3UT6jLh0WQ5Dx7M8axUflllKiSJpFIBm7fW/C/LTCjE+OPFrexl9ks/1m+tKYHw/Y2Rzs19ZIuiGgDxVsrUvFkZdURtxew0t3aSUu7Ywa0Msxr5x1XPgfNh/w7/U8EX6v0= ; Message-ID: <20060428061105.37423.qmail@web54215.mail.yahoo.com> Received: from [64.81.86.61] by web54215.mail.yahoo.com via HTTP; Thu, 27 Apr 2006 23:11:05 PDT Date: Thu, 27 Apr 2006 23:11:05 -0700 (PDT) From: "J." Subject: Re: connection pooling with servlets To: pgsql-jdbc@postgresql.org In-Reply-To: <4451A813.6030403@vailsys.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1530396706-1146204665=:37410" Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200604/181 X-Sequence-Number: 15115 --0-1530396706-1146204665=:37410 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Thanks. I posted some of the relevant code here; http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=7&t=016798 But I'm still baffled as to how to get access to a session in a servlet that was called by a jsp. Should servlets have access to sessions easily? Everyone is making it seem like this shouldn't be a problem, but then I've read in other places that a jsp calling a servlet clears whatever attributes were part of the request object. David Durham wrote: J. wrote: > Thanks for replying. I'm not sure if that would help, but maybe if I > understand the suggestion better it will. > > Right now I've got the index.jsp calling Login servlet via POST. Then > Login creates the connection, puts it into a session with some other > attributes and forward(req,res) to welcome.jsp. Not much point in storing a datasource as a session attribute (1 datasource per application user?). More appropriate to make it application-wide by putting a datasource in a servlet context or, as someone else suggested, a static attribute/property/member/variable ... request.getSession().getServletContext().setAttribute(...). JNDI is another good place to put this sort of thing. An easy way to make sure your datasource is always available is to use a servlet context listener to create it when the application is initialized. Google for servlet context lifecycle should tell you how to do setup a listener. Now, as for a null pointer on your connection object, maybe you have something misconfigured in your datasource. Username, password, host, and driver class are usual suspects. > Welcome.jsp has a form > that uses GET to call a Search servlet and this is where I get a null > pointer on the connection object. I'm trying to get the session out of > the request object, but it seems like the request loses state by the > time I'm getting to it (in Search servlet). Not sure. You can post your code and maybe get some help. Wait, is this homework? -Dave --------------------------------- Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less. --0-1530396706-1146204665=:37410 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Thanks.  I posted some of the relevant code here;

http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=7&t=016798

But I'm still baffled as to how to get access to a session in a servlet that was called by a jsp.  Should servlets have access to sessions easily?  Everyone is making it seem like this shouldn't be a problem, but then I've read in other places that a jsp calling a servlet clears whatever attributes were part of the request object.

David Durham <ddurham@vailsys.com> wrote:
J. wrote:
> Thanks for replying. I'm not sure if that would help, but maybe if I
> understand the suggestion better it will.
>
> Right now I've got the index.jsp calling Login servlet via POST. Then
> Login creates the connection, puts it into a session with some other
> attributes and forward(req,res) to welcome.jsp.

Not much point in storing a datasource as a session attribute (1 datasource per application user?). More appropriate to make it application-wide by putting a datasource in a servlet context or, as someone else suggested, a static attribute/property/member/variable ... request.getSession().getServletContext().setAttribute(...). JNDI is another good place to put this sort of thing. An easy way to make sure your datasource is always available is to use a servlet context listener to create it when the application is initialized. Google for servlet context lifecycle should tell you how to do setup a listener.

Now, as for a null pointer on your connection object, maybe you have something misconfigured in your datasource. Username, password, host, and driver class are usual suspects.


> Welcome.jsp has a form
> that uses GET to call a Search servlet and this is where I get a null
> pointer on the connection object. I'm trying to get the session out of
> the request object, but it seems like the request loses state by the
> time I'm getting to it (in Search servlet).

Not sure. You can post your code and maybe get some help. Wait, is this homework?


-Dave



Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less. --0-1530396706-1146204665=:37410--