My web.xml doesn't know the taglib tag
I want to use html tags in my jsp, so I need to add the lib tag to web.xml when I add these lines to web.xml:
<taglib>
<taglib-uri>/tags/struts-html</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
he doesn't know the taglib tag
<taglib>
must be inside the tag <jsp-config>
.
But using Struts2
, you absolutely don't need the struts-html
taglib, it's from Struts 1, which is older and completely different.
Just browse through the features Struts2
and you will find that you no longer need to use html tags, thankfully.
In newer versions of JSP / Servlet containers, the taglib entry is not required web.xml
as the containers will automatically find it.
You only need a directive <%@ taglib %>
in your JSP page to use .tld files:
<%@ taglib prefix="html" uri="/WEB-INF/struts-html.tld" %>
There are three ways to customize a tag library.
- Manual throw setting
web.xml
: Make sure the tld files are copied to the folderWEB-INF
, set themweb.xml
as below, use the taglib attribitete attribute in the taglib directive like<%@ taglib uri="mytagliburi" prefix="ww" %>
.
...
<taglib>
<taglib-uri>mytagliburi</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
- Manual configuration with directive only
taglib
. Make sure the tld files are copied to the folderWEB-INF
and configure directly in the taglib directory as<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="ww" %>
. - Automatic setting . This is an easy way and is used in Struts version 1.2, just include it
struts-taglib.jar
in the projectclasspath
or copy it to a folderWEB-INF/lib
. All details aretld
defined inside the folderstruts-taglib.jar\META-INF\tld
. During deployment, all tlds will be deployed automatically. However, we can only access it using the namepre-fixed uri
. In this method, we cannot change the nametaglib uri
.