Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP: Is it possible to use custom tags in a servlet?

 
Daniela Meyer
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there
I am trying to use a custom tag in a servlet:

The code above is simply ignored. Does anyone have any clues on this?
Thanks!
Daniela
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using them that way, no it's not possible unless you port the output to a file named .jsp and forward the request to the generated page.
Remember, Tags and the like on a JSP are Parsed into a java file and compiled. The container then executes the Java class file. Using the PrintWriter off the response sends the text unchanged to the browser (I know, filters and the like can modify the response but, we won't discuss that right now.)
You need to ask yourself what do you need from that Tag class? Once you determeine that, factor it out into a Poor Old Java Object and have the servlet and Tag use it.
 
Daniela Meyer
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much, Carl!
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!