• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

someone pls explain me this statement...

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Attributes bound into a session are available to any other servlet that belongs to the same servletcontext.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlets belonging to the same ServletContext (same app) can all access the same session, thus they can access the same objects with are bound to this session.
 
Shruthi Karthick
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My understanding is like :
Session attributes(Attributes bound into a session) are availbale to the all the servlets that are part of the same session.
But how it can be accessed by all servlets which are part of same servletcontext?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that you are mixing ServletConfig and ServletContext :
Servlet 1:1 ServletConfig
Servlet n:1 ServletContext
 
Shruthi Karthick
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am talking abt session attributes and Servletcontext attributes...

Session attributes are available to all servlets which are part of same session...

Context attributes are accessile to all servlets in web app...

Statement : Attributes bound into a session are available to any other servlet that belongs to the same servletcontext.

My Doubt : Attributes bound into a session are available to any other servlet that belongs to the same session.
[ March 19, 2008: Message edited by: Shruthi Karthick ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Session attributes are available to all servlets which are part of same session...


Servlets are not part of a session. What makes you think that ?

Statement : Attributes bound into a session are available to any other servlet that belongs to the same servletcontext.


True. Because multiple servlets run in the same context (same web app)
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sessions and Servlets and two different beasts. A request may be associated with a session, and forwarded by the container to the appropriate servlet. Servlets do not live in sessions, and are not associated with sessions either. Servlets can retrieve a session from a request, to set/get attributes. That's about it.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Servlets belonging to the same ServletContext (same app) can all access the same session, thus they can access the same objects with are bound to this session



Here my intenstion is to make the above statment clear.

Suppose for example there are two servlets, Serv1,Serv2 and Serv3 in a web app. So Serv1, Serv2 and Serv3 will be in same ServletContext.

For the logging Serv1 will be used.

Customer1 made a login request and session1 is created. For this session1 an attribute "Valid for PMT" is added allowing customer to make a payment.

request.setAttribute("isValid","Valid for PMT")

Customer2 made a login request and session2 is created. For this session2 an attribute "Not Valid for PMT" is added allowing customer not to make any payment.
request.setAttribute("isValid","NotValid for PMT")

In your web app you are allowing payments to do online.For this Payment Transaction Serv2 is used.

When Customer1 makes a payment, In Serv2 to validate the customer the logic will be

String valid = (String)request.getAttribute("isValid");

This will return - Valid for PMT

When Customer2 makes a payment, In Serv2 to validate the customer the logic will be

String valid = (String)request.getAttribute("isValid");

This will return - Not Valid for PMT

And in your app you are allowing customers to make online balance transfer even. Condition here is, the customers who are valid for payment only can be allowed to make Balance Transfer online. Here Serv3 will be used
to check this.

So in the Serv3 again to validat BT we can access the same session attributes which were set as a part of payment.

Customer1 : String valid = (String)request.getAttribute("isValid");
Customer2 : String valid = (String)request.getAttribute("isValid");

In this way until you make that session variable invalid (as per your business logic) or session expires, you can access this session variable in all servlets which are in the same servletcontext (same web app).


Hope this example will make you clear. If example is bad, don't scold me.

Here the Servlets acts as controller(to perform business logic). Servlet is indepent of session.
[ March 19, 2008: Message edited by: kalle suresh ]
 
Shruthi Karthick
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your clarification...
suresh your example is very good
one thing...you used
request.setAttribute("isValid","Valid for PMT")
but it should be
session.setAttribute("isValid","Valid for PMT")
[ March 19, 2008: Message edited by: Shruthi Karthick ]
 
kalle suresh
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you are right, that should be session1.setAttribute() and session2.setAttribute() like that.
[ March 19, 2008: Message edited by: kalle suresh ]
 
What's that smell? I think this tiny ad may have stepped in something.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic