• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trying Head First Servlet and JSP chap 10 Example for Custom tags  RSS feed

 
Rohit Gaikwad
Ranch Hand
Posts: 40
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple tag handeler code


JSP Page


and the error i am getting is ---



I am New o Please HELP

Thanks In advance
 
Rohit Gaikwad
Ranch Hand
Posts: 40
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Updates

I thought that myTag.tld file is not getting detected or the tag in not getting detected so Declared
taglib under web.xml file
But still getting the same error

So still waiting for reply from Experts
Thanks
 
Stefan Evans
Bartender
Posts: 1834
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rohit.

I think your problem is caused because your SelectTagHandler class is not in a package.
Try putting the class in a package (don't forget to update the reference from the tld) and then try it again.


 
Rohit Gaikwad
Ranch Hand
Posts: 40
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stefan Evans
Solution Worked !!!
But Can you please tell me why it was not working with Default package ?
And should i always built my tags in a package ??
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All classes should be placed in a package. Period.

But this is especially important in a web application where the concept of "current directory" is nebulous at best.
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The basic reason why is that classes in the "default" package (i.e. no package) are not visible to classes that ARE in a package.
This was a change back in Java 1.4 I think - to close a security loophole.

The Tomcat classes running your tag are in a package. Because your tag wasn't in a package, Tomcat couldn't find it - hence the error message "SelectTagHandler cannot be resolved to a type"
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!