• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing implicit objects in declarations?

 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The implicit objects are defined locally inside _jspService(...) method and they are NOT accessible in declarations.
Is it considered a good practice to access them outside the _jspService method (by one means or another)? Looking for some guidance on this. Pros/Cons
Thanks.
- satya
 
Chintan Rajyaguru
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the implicit variables are defined inside _jspService method, there is no way you to access them unless you define a variable in higher scope and assign implicit variable to it.
Based on what I know, the only logical place to access implicit variables is in doXXX methods of custom tags.
A bad programming practice could access them outside the _jspService methods but then you loose the basic characteristics (such as thread safety).
I eould love to see more comments...
Chintan
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
loose the basic characteristics (such as thread safety).
implicit objs are never gaurenteed to be thread safe. Some of them are, because of their nature, but there's nothing basic abt that...
- satya
 
Ram Dhan Yadav K
Ranch Hand
Posts: 321
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Chintan.
Is it considered a good practice to access them outside the _jspService method (by one means or another)?
What do you mean by outside _jspService, is it outside the scope of the _jspService or in a user defined method which is with in the scope of _jspService i.e private methods which you access only with in jspService method. Then it should be legitimate and should workfine.
But if you try to access them outside the scope of _jspService, you will end up sending one customers bill to another customer
Would like to hear more comments.
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What do you mean by outside _jspService, is it outside the scope of the _jspService

That I agree to.
or in a user defined method which is with in the scope of _jspService i.e private methods which you access only with in jspService method. Then it should be legitimate and should workfine.

Say I define a private method using a declaration
private void myJunkJSPMethod(JSPWriter out)
{
// implementation
}
and call this from inside the _jspService(...) method passing it the implicit out obj.
Is that good/bad?
I agree with Chintan, thats bad, theoritically.
But just curious if there's a situation when anyone did this?
Maybe I am splitting hairs.... :roll:
Thanks.
- satya
 
Ram Dhan Yadav K
Ranch Hand
Posts: 321
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure about JSP, but i did the same stuff with servlets and it workd fine. There is not prblem even with load tests and the code does not break on production. I guess it working fine as of now!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic