• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt about getAttribute of Session

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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")
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ??
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
reply
    Bookmark Topic Watch Topic
  • New Topic