File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes servlet versus a custom tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet versus a custom tag" Watch "servlet versus a custom tag" New topic

servlet versus a custom tag

Sharon Ross

Joined: Sep 25, 2003
Posts: 13
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,

a belly dancing programmer<br />both artistic processes
Brian R. Wainwright
Ranch Hand

Joined: Aug 12, 2003
Posts: 92
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.
I agree. Here's the link:
subject: servlet versus a custom tag
It's not a secret anymore!