• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
  • Tim Holloway
  • Carey Brown
  • salvin francis

Problem with TagLib

Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a TagLib which is working perfectly with JSPs,The Tag is

<c:chart id="chart1" datasource="#{name.Graph}" type="xyline" is3d="false" background="green" height="50" width="150" legend="false" border="true"> </c:chart>
. What i am trying to do is set the values of the Taglib Class from within a Servlet Execute it and return back the HTML codes which would otherwise have been returned by the Taglib sitting on a JSP. I have already set the Values

Posts: 67279
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bad idea. If I understand what you are doing, you are trying to invoke the tag from a servlet reather than a JSP. Since each container will take proprietary steps to perform this action, you're looking at adding container-specific code into your servlet.

Rather, refactor your tag such that it gathers the necessary data from the tag attributes and calls another helper class to format the output. The helper class can also then be directly invoked by a servlet.

This assumes a tag with an empty body. If there is JSP body content that needs to be evaluated, all bets are off.

So why are you trying to do the job of a JSP in a servlet in the first place?
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I must have been writing this at the same time as Bear, and he just got in first, so I apologise if much of this is the same:

You can't easily do this because the runtime environment of a JSP is slightly different to that of a Servlet - for example, JSPs require PageContext, a JspWriter, scoped attributes, EL parsers and resolvers etc. and it is the JSP engine which manages the lifecycle of a tag and makes sure these objects are available. If your tag was supposed to have body content for example, and you wanted to include scriptlets in it, or you include an EL expression in an attribute (as you have done), what would you (and the container) do?

So you've got a choice: either you can try to hack your specific container to artificially create a proper runtime environment (which is a really bad idea but also a lot of work), or you can redesign your application.

If you really do need to access tag functionality from a servlet (even though a servlet shouldn't really generate textual content as this job is better done by a JSP), perhaps you should put that tag functionality in an independent JavaBean helper, accessed by both the servlet and the tag handler. That way you can do exactly what you need programmatically from both sources.

As I say, if you're really generate a lot of text, you'd be better just using a JSP and using RequestDispatcher to forward to it anyway. You can use a (Http)ServletResponseWrapper when doing the forward if you don't want to put the content of the JSP into the response stream directly.
[ May 08, 2006: Message edited by: Charles Lyons ]
F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
Enterprise-grade Excel API for Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!