• Post Reply Bookmark Topic Watch Topic
  • New Topic

To keep track of scope in JSP  RSS feed

 
Doshi Milan
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Friends,
How does the Web Server internally keep track of the different scope objets in case of JSP.
i.e : If e define an object O1, say ,with application scope and another Object O2 with scope session, than how will the server internally keep track that O1 has application scope and hence should not die and so on.
Thanks in advance,
Regards,
Milan Doshi
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've always just trusted the API to do it's job.

If I stick something in the application attribute space, then I expect it to be there until the application goes away. I'm not really concerned with the details.

To me, it's like wondering how the JVM keeps ints and long separate.

Is this another interview question?
 
Doshi Milan
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mike,
Yes you guessed it right . It was a qtn asked in an interview. I guess I should not bother about such things.
Thanks and regards,
Milan
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Curwen:
[QB]
To me, it's like wondering how the JVM keeps ints and long separate. QB]

Well, that... and I'd expect its also highly vendor-dependent... sort of an odd question.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is certainly vendor dependent -- but most vendors do things similarly. My advice to you would be to go download the source code for TomCat and read it to find out how the reference implementation does it.
You shouldn't be too surprised to find out:
(a) Putting things in application scope means adding them to a global Map
(b) Putting them in Request scope means adding it to the HttpRequest object
(c) Putting them in Session scope means adding them to the HttpSession object. (Of course, this one gets VERY interesting and vendor-dependent after that)

Kyle
 
Soma Sekhar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Do you have any idea about what's happening when a .jsp file is turned in to .java file?A servlet file will be created by the server.Do you know how the server is taking care of a JSP file being turned into a servlet file?What's happening to the tags that you wrote in your .jsp file? If you write bean tags like
<jsp:useBean id="xxx" class="pack1.pack2.XXX" scope="application"/>
<jsp:useBean id="yyy" class="pack1.pack2.YYY" scope="session"/>
how the server/servlet engine is interpreting these tags ?
If you say 'scope="application"' for an object xxx of class pack1.pack2.XXX then a new object is created with default constructer of that class and that object is set in the ServletContext object of that application i.e "application" is nothing but an instance of ServletContext.The "xxx" object is set into that ServletContext's instance as
application.setAttribute("xxx",new pack1.pack2.XXX());
Similar is the case with scope "session" also. The instance of class pack1.pack2.YYY is set into HttpSession object as
sesison.setAttribute("yyy",new pack1.pack2.YYY);
Hope your doubt is clarified.If you have any other doubts in this regard do not hesitate to contact me.
Regards
Soma.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!