This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have the need to take an xml data source and do a transform with an xsl template. I have written it as a servlet and as a custom tag. Both work. My question is, when would be best to implement it as a servlet and when would it be best to implement it as a custom tag? The servlet is currently being used by multiple sites that need the transformed data (we return the data in html or wml format as requested). The custom tag is a proof-of-concept implementation. I wasn't quite sure how to do it and wanted to see if I could. It would (yes, life is subject to change, but for this round...) always be called from a JSP. Does this seem right? Are their resource issues to take into account? Any insight is appreciated, Sharon
a belly dancing programmer<br />both artistic processes
Hi Sharon, I think you kind of answered your own question believe it or not. From the perspective of a JSP/Servlet application, if the required transformation is always going to be called from with a JSP, then a custom tag is a better implementation. What you seem to be doing is formatting data for display. Sticking to the Model-View-Controller pattern (v2) this is a View-centric task and a View-centric solution would therefore be best (as opposed to the Controller/servlet which should simply dispatch requests to the appropriate View). Writing it as a custom tag better follows the pattern and allows for greater ease of portability and reuse. Also your JSP developers (in my case and probably yours this is you) would be able to use the tag wherever they needed. These are all advantages of a custom tag that I'm sure you're familiar with. As far as performance considerations... I can't think of any... the JSP gets turned into a servlet by the servlet container, so I'd imagine that performance would be the same. On the other hand, I can imagine that the presence of an intensive tag could make it appear to take longer becauce the screen make take longer to draw. That's my two cents.