• Post Reply Bookmark Topic Watch Topic
  • New Topic

Custom Tag vs Java in JSP performance

 
Joshua Elkino
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How does performance compare whether i'm purly injecting java code into a jsp page rather than creating a custom tag lib and passing values to it?

I know its good practice to keep java away from a jsp page thus creating taglibs, but is there a performance hit to doing this?

Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The performance differences between the two are negligible.
 
Joshua Elkino
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So becides this "best practice" is there any other reason than reusibility to use custom tags? I see it just as easy if not easier to just copy/paste java code into jsp, rather than create a seperate class and modify config files, etc...
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilya Elkind:
I see it just as easy if not easier to just copy/paste java code into jsp, rather than create a seperate class and modify config files, etc...


Have you ever tried to maintain/modify an app with a hundred or more JSPs containing cut and pasted Java code in scriptlets?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even using custom tags, if you are doing a lot of processing in the JSP you are not using modern accepted practices. JSPs should be used purely for view rendering. All other processing and decision making should be handled in controllers invoked prior to the JSP.

Putting Java code in JSPs at this point is taking two steps back!
 
Joshua Elkino
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see your points, but to play the devils advocate, how about this.

Since as far as i know you can only pass string values to tags, doesn't it take more time to retrieve/modify/display objects from the taglib class?

In a jsp i would just use my object to work out the logic, but with a tag, i would have to store that object in a session var, then in the tag, retrieve the session var, then work out the logic...

rebuttals?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilya Elkind:

Since as far as i know you can only pass string values to tags,


This is incorrect.
You pass can pass object references as well (a String is an object in Java).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!