aspose file tools*
The moose likes Servlets and the fly likes Servlets calling a Custom Tag - Possible? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets calling a Custom Tag - Possible?" Watch "Servlets calling a Custom Tag - Possible?" New topic
Author

Servlets calling a Custom Tag - Possible?

Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi,
Since JSP's are made on the Servlet Technology,I suppose, we can always say whatever can be done through JSP the same would be possible through Servlets
However, the concept of Taglibs is absent in Servlets.Can we call Taglibs in the Servlet code?
Since TagLibs might contain some business logic, which the page-makers usually use to incorporate in the pages, it would be great if similar sort of facility would be available through servlets
Thanks in advance,


------------------
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56


<b>Sandeep</b> <br /> <br /><b>Sun Certified Programmer for Java 2 Platform</b><br /> <br /><b>Oracle Certified Solution Developer - JDeveloper</b><br /><b>-- Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java </b><br /><b>-- Object-Oriented Analysis and Design with UML</b><br /> <br /><b>Oracle Certified Enterprise Developer - Oracle Internet Platform</b><br /><b>-- Enterprise Connectivity with J2EE </b><br /><b>-- Enterprise Development on the Oracle Internet Platform </b>
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
You correctly note that since JSP's are ultimately translated into servlets, you can do anything with servlets.
You can theoretically call custom tags from within a servlet, if you're willing to do a lot of work, but the syntax is ugly. All you have to do is duplicate the calling sequence that the JSP container generates:

You would have to implement the PageContext with your own class.
If you have code in a tag handler that you want to use in both environments, you would be better off implementing it in a pure Java Beans model class, which you call from the tag handler. That way, you could call the model from a servlet without having to go through the semantics of the taglib code.
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
Website: http://www.philhanna.com


Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
Anil Vupputuri
Ranch Hand

Joined: Oct 31, 2000
Posts: 527
Originally posted by Phil Hanna:
you would be better off implementing it in a pure Java Beans model class, which you call from the tag handler.

Yeah it is easy to use Java Object's in servlet rather going for the tag handler which makes things complicated. I dont see any advt. using tag handler in Servlet......is there any??

SCJP 1.5, SCEA, ICED (287,484,486)
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Thanks Phil and Anil for your response.
Anil, as I said in my earlier post, we have some business logic in the taglibs.From the responses that you and Phil gave, should I infer that, if I have to call my business logic in Servlets and JSP, I would be better off to put that piece of code in the JavaBean (ofcourse,EJB would be the best solution!!) rather than the taglibs.
Thanks in advance,
------------------
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Servlets calling a Custom Tag - Possible?