• Post Reply Bookmark Topic Watch Topic
  • New Topic

Scriplets Over-use

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am learning JSP and am wondering if someone could provide me with a link or resource of some sort that specifies a "rule" as to when to use a servlet instead of a scriplet?
Simply, at what point do we take our scriplet and decide it needs to be a servlet?
Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65528
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know of any site that list such "rules", and you're likely to get a LOT of opinions on this, but here's the very loose rules of thumb I use for my own code:
1. As much as possible keep scriplets off the page
2. I almost exclusively use a model 2 approach and perform any processing in a servlet that forwards to the JSP with all the "hard work" already done
3. Any scriplet that DOES appear on the page should be there as a "display helper"... e.g. formatting, iteration, and so on. If the scriplet does "real work" it goes in the servlet.
4. If the scriplets start forming a pattern used over and over again, or if it's something that's complex and makes the page look really gnarly, it gets factored out into custom tags.
Pretty loose, I know, but it seems to work to keep my pages pretty simple and easy to maintain/extend.
hth,
bear
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear. So if I may ask, can you expand a little on your approach to writing a Custom Tag over putting the code in a scriplet?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!