Even if this question has an (to me, incomprehensibly) accepted answer, I feel obliged to have a go at it myself. The real answer is contained in BalusC's comment and suggesting stray .tld
files laying around in WEB-INF
is really bad advice. My intention is expand on this using the exact version of Struts2 the OP was asking about (v2.1.8), which I downloaded from Apache's historical archive.
I don't know in which .jar file the struts-html.tld file is located.
There is no struts-html.tld
in Struts2 - Instead there are the following:
struts-tags.tld
, which resides in the META-INF
directory of struts2-core-2.1.8.jar
and contains all standard Struts tags, like the ones you'd expect to find in struts-html.tld
in Struts1.
tiles-jsp.tld
, which resides in the META-INF
directory of tiles-jsp-2.0.6.jar
and corresponds to what was struts-tiles.tld
in Struts1.
- some more TLDs, e.g. for SiteMesh which are not directly related to the question.
I want to use html tags, specified in a taglib directory provided by Struts, in a JSP page. But don't know how to use it. I know how to use taglib directive but I came to know from sources that the .tld file has been embedded in a .jar file after version 1.2.8.
That is correct. The way it generally works is the following:
- When the servlet container starts up, it looks through the
WEB-INF/lib
directory and loads any .jar
files it finds there - This is where you need to place the Struts2 library.
- Inside these
.jar
files, any TLDs are expected to reside in the META-INF
directory. Obviously and as mentioned above, this already is the case for struts2-core-2.1.8.jar
, so there's nothing that needs to be done.
- When the servlet container loads the TLD, it looks for the
<uri>
element inside the root element <taglib>
and stores a mapping between that TLD and its URI. Correspondingly, this URI is used in your .jsp
files to reference the TLD.
In the case of struts2-core-2.1.8.jar
, the URI is /struts-tags
and thus you need to reference it in a .jsp
file like this (of course you can change the prefix
attribute to your liking)...
<%@ taglib uri="/struts-tags" prefix="s" %>
...and subsequently put it to use, like e.g. this:
<s:form action="HelloWorld">
(...)
</s:form>
/WEB-INF
with loose TLD files. Just dropping the JAR file(s) in/WEB-INF/lib
and declaring the taglibs in top of JSP as per the TLD documentation is sufficient to get JSTL to work. That ought also be the normal practice for all the other JSP taglibs: 1) drop JAR file(s) in classpath (i.e./WEB-INF/lib
), 2) declaretaglib
in JSP. That's all. Similar answer: stackoverflow.com/questions/2323645 – Butt