File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Doubt about getAttribute of Session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Doubt about getAttribute of Session" Watch "Doubt about getAttribute of Session" New topic
Author

Doubt about getAttribute of Session

Haroldo Nascimento
Ranch Hand

Joined: Aug 14, 2003
Posts: 79
Hi
I can get Attribute ( Session.getAttribute() ) of de session that were put in the session for other Web Application that is in the same web Server ?
Exemple:

webapps/App_A
1- create session
2- request.getSession().setAttribute("Valor", valor)
...

webapps/App_B
request.getSession().getAttirbute("Vlor")
Afroz Ahmed
Ranch Hand

Joined: Jan 18, 2004
Posts: 64
Try like below..hope it will work
webapps/App_A
1- create session(HttpSession session1...)
2- request.getSession().setAttribute("Valor", valor)
3- getServletContext().setAttribute("App_A_session",session1);
...

webapps/App_B
- getServletContext().getAttribute("App_A_session").getAttirbute("Vlor");
Regards
Afroz Ahmed
SCJP 1.4
SCWCD..on the track
[ March 08, 2004: Message edited by: Mohd Afroz Ahmed ]

The value of an idea lies in the usage of it.
Haroldo Nascimento
Ranch Hand

Joined: Aug 14, 2003
Posts: 79
I intends insert in the session User Perfil after login. If I to use getServletContext to guard User Perfil, it can lost the Perfil when more that one user login ?
Haroldo Nascimento
Ranch Hand

Joined: Aug 14, 2003
Posts: 79
Afroz,
It dont works. Read it:
"
public abstract interface ServletContext
Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file.
There is one context per "web application" per Java Virtual Machine. (A "web application" is a collection of servlets and content installed under a specific subset of the server's URL namespace such as /catalog and possibly installed via a .war file.)
...
"
Then, It impossible to passe and access attibutes of the a web application to other in the same web server ??
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Actually, you CAN get the attributes out of another webapp running in the same server, but it has to be enabled. Check out the ServletContext.getContext() method.


James Carman, President<br />Carman Consulting, Inc.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29253
    
139

Some servers disable this. In the API link you posted, it says:
In a security conscious environment, the servlet container may return null for a given URL.

I thought I read something a while back about this not being in the spec too.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
For security it's not recommended to do things like that, and indeed servers can have it disabled.
If you MUST communicate with another webapp, you might want to do so either via HTTP requests back and forth or through some custom network protocol (this also will enable you to keep your scheme working if one or the other webapp moves to another machine for whatever reason).


42
 
wood burning stoves
 
subject: Doubt about getAttribute of Session
 
Similar Threads
session problem
Not get the session value
using same value in multiple pages...
STRUTS : diff between JSP implicit session object and HttpSession object
When is a HttpSession object created by the Web Container