• Post Reply Bookmark Topic Watch Topic
  • New Topic

request or variable  RSS feed

 
Matt Wielbut
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Performance wise, should you create variables to store header values at the start of a jsp or servlet and refer to those variables when grabbing the info later on, or should you just make calls directly to the request object.
Ex:


just wondering..
 
Ronald Francis
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shouldn't make a difference but u'd probably find it cleaner to get it up front ( to do some null checks , etc )
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Performance wise, no difference. Space for a local variable will be allocated by the JVM in either case - whether you've given that variable a name or not.
 
Steven Daniels
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't it depend on how many times you want to use the value in the jsp? For instance if I wanted to display the "username" parameter 10 time on a page, it would make sense to store it to a local variable. Not only would it be less typing, the jvm would not have to make an actual method invocation to get the value every time.
If I only want to display it once, then it would make sense to just display it from the request.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, right. The moment you're using the value more than once, it becomes more efficient to use a named variable so as to re-use the previously retrieved value, rather than calling another method. I was only talking about the difference between the two code examples shown, where the value is only used once.
[ August 09, 2002: Message edited by: Jim Yingst ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!