Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt about getAttribute of Session

 
Haroldo Nascimento
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Haroldo Nascimento
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic