This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes How to share a user-connection between two projects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to share a user-connection between two projects" Watch "How to share a user-connection between two projects" New topic
Author

How to share a user-connection between two projects

Karl-Heinz Kott
Greenhorn

Joined: Dec 30, 2010
Posts: 5
Hello,

i need some help,

I have two GWT-projects: "login" and "webapp".
The user has to logon to my server with his credentials. The login-project has one servlet class with several servlet methods. At initialization of the servlet the "init" method will be called:




The ServletContext object gets an attribute "currentConnections" to store a ConnectionPool object.
The ConnectionPool object stores the connection from the given user in a HashMap with the given SessionId:



The user will be directed to "webapp"-application...
--------------------------------------------------

In my "webapp"-project i try to retrieve this stored connection for the user:



The con is always == null !!!
I think the scope of ServletContext with his attribute is to restricted?!?
My sessionId is possibly also a different in the "login" and the "webapp"-application.

Is there a better solution to share a user-connection between two web-apps?

I appreciate any advice!
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

First of all , Each web Application has got its own ServletContext , so storing in ServletContext isn't appropiate .
Share a user-connection between two web-apps?

By connection you mean Database connection or User session ??


Save India From Corruption - Anna Hazare.
Karl-Heinz Kott
Greenhorn

Joined: Dec 30, 2010
Posts: 5
Hello Ravi Kiran Va,

i try to hold a database connection object in a connection pool
and share this object between this both apps.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

i try to hold a database connection object in a connection pool
and share this object between this both apps.


First of all sorry for the late reply.

You should not hold the Database connection too long , and still if you want to continue then
I guess what you were doing is an internal Application ( used within some Organization and not more than 30 users accessing simultaneously) If this is the case you can proceed doing so .

Please answer me this ??
Why do you want to Pass Database Connection Object ?? rather than getting it from Connection pool ?? Is it possible for you to explain the Scenario ??

Thanks .
Karl-Heinz Kott
Greenhorn

Joined: Dec 30, 2010
Posts: 5
I guess what you were doing is an internal Application ( used within some Organization and not more than 30 users accessing simultaneously) If this is the case you can proceed doing so .


Every user has his own account in DB, so every user should get his own connection.
It`s not intended to share one connection between two ore more users. Btw. security concept is controled by DB.
The connection will be aborted by DB after a certain time -> users will be prompted to logon again.

Why do you want to Pass Database Connection Object ?? rather than getting it from Connection pool ?? Is it possible for you to explain the Scenario ??


I need to store this database connection object because of my two projects. In my logon-project, the user authenticates himself -> con-object will be
stored in the connection pool. Afterwards i direct the user to the webapp-project with Window.open(url...).
Then the user can do some requests to server (using servlets). On server side the connection object must be taken out of the connection pool
to make a request to the DB.

Again: How can i store this connection in a global "container" (servlet-context?) to hold an take it from it?
Karl-Heinz Kott
Greenhorn

Joined: Dec 30, 2010
Posts: 5
Any ideas? Is there maybe a workaround?
I need a quick (and if so dirty) solution...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to share a user-connection between two projects
 
Similar Threads
Running servlet from bean
Maintaining scalability in servlets programming
DB connection from servlets
Last Minute Reference
Accessing the servletContext outside of a servlet