Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tag body uses an expression

 
Prashant Shiralkar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

The following code is a test implementation for "Sharpen your pencil", in book: Head First Servlets and JSP, Edition 2, Page# 519. In the process, I figured out that the body (the EL expression ${movie}) of the custom tag <myTags:simple4></myTags:simple4> is not getting evaluated and being treated as template text. When I inspect the generated servlet (.java) file corresponding to the JSP page, I find that there is container specific method call for the outer EL expression (hence, in the output its being evaluated), but the body of custom tag is simply being sent as template text. I don't see a reason for this. Any clue why this could be so? or am I going wrong somewhere? (Moreover, nowhere in my app have I any setting to ignore EL.)

JSP:

TLD:
Tag Handler class:

 
Keith Flo
Ranch Hand
Posts: 128
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prashant,

'tagdependent' means .... dont evaluate the body ... rather ... send it as plain text ... see p. 508 in K&B. If you change it to 'scriptless' the body will be evaluated.
 
Prashant Shiralkar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Keith, I misinterpret the body-content type. A related problem I faced while implementing this was that, at request time, it gave a compilation error for the generated servlet file corresponding to the JSP page. To get around this, I placed the TagHandler.class file in the same directory as the servlet java file. Ideally, tomcat should be able to find the class file in /WEB-INF/classes directory, but looks like it didn't. Do you see any reason for this?
 
Keith Flo
Ranch Hand
Posts: 128
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need a package statement ... see the example on p. 513. I think that might be the problem.

I know for certain that tomcat will find your classes if you place them in WEB-INF/classes. I've got several custom tags I've written all in WEB-INF/classes.

Anyway, its just good Java coding practice to put your classes in a package and not to use the default package.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic