Struts - Taglib directive on JSP page for .tld provided by Struts

I am developing an application based Struts. I am new to Struts. I want to use the tags htmlspecified in the taglib directory provided Strutson the page JSP.

But I don’t know how to use it. I know how to use the taglib directive, but I learned from sources that the .tld file was embedded in the .jar file after version 1.2.8. I am using Struts version 2.1.8.

I do not know which .jar file the file is in struts-html.tld.

+5
source share
3 answers

I am using Struts 1.3.10 for this illustration:

  • (http://struts.apache.org/download.cgi#struts1310). , - , , TLD Struts.
  • - , /WEB-INF/lib.
  • JSTL ( ) (http://java.sun.com/products/jsp/jstl/)
  • , TLD Struts JSTL Tld, /WEB-INF/tld/ ( /WEB -INF/).
  • web.xml ( <web-app>)

      <jsp-config>
        <taglib>
            <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
            <taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
            <taglib-location>/WEB-INF/tld/struts-html.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
            <taglib-location>/WEB-INF/tld/struts-logic.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>
            <taglib-location>/WEB-INF/tld/struts-nested.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
            <taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/sslext.tld</taglib-uri>
            <taglib-location>/WEB-INF/tld/sslext.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/struts-layout.tld</taglib-uri>
            <taglib-location>/WEB-INF/tld/struts-layout.tld</taglib-location>
        </taglib>
    
        <!-- Sun JSTL -->
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/fn</taglib-uri>
            <taglib-location>/WEB-INF/tld/fn.tld</taglib-location>
        </taglib>
    
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
            <taglib-location>/WEB-INF/tld/fmt.tld</taglib-location>
        </taglib>
    
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/fmt-1-0</taglib-uri>
            <taglib-location>/WEB-INF/tld/fmt-1_0.tld</taglib-location>
        </taglib>
    
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/fmt-rt</taglib-uri>
            <taglib-location>/WEB-INF/tld/fmt-rt.tld</taglib-location>
        </taglib>
    
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/fmt-1-0-rt</taglib-uri>
            <taglib-location>/WEB-INF/tld/fmt-1_0-rt.tld</taglib-location>
        </taglib>
    
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
            <taglib-location>/WEB-INF/tld/c.tld</taglib-location>
        </taglib>
    
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/core-1-0</taglib-uri>
            <taglib-location>/WEB-INF/tld/c-1_0.tld</taglib-location>
        </taglib>
    
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/core-rt</taglib-uri>
            <taglib-location>/WEB-INF/tld/c-rt.tld</taglib-location>
        </taglib>
    
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/core-1-0-rt</taglib-uri>
            <taglib-location>/WEB-INF/tld/c-1_0-rt.tld</taglib-location>
        </taglib>
    
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
            <taglib-location>/WEB-INF/tld/sql.tld</taglib-location>
        </taglib>
    
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/sql-1-0</taglib-uri>
            <taglib-location>/WEB-INF/tld/sql-1_0.tld</taglib-location>
        </taglib>
    
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/sql-rt</taglib-uri>
            <taglib-location>/WEB-INF/tld/sql-rt.tld</taglib-location>
        </taglib>
    
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/sql-1-0-rt</taglib-uri>
            <taglib-location>/WEB-INF/tld/sql-1_0-rt.tld</taglib-location>
        </taglib>
    
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
            <taglib-location>/WEB-INF/tld/x.tld</taglib-location>
        </taglib>
    
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/x-1-0</taglib-uri>
            <taglib-location>/WEB-INF/tld/x-1_0.tld</taglib-location>
        </taglib>
    
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/x-rt</taglib-uri>
            <taglib-location>/WEB-INF/tld/x-rt.tld</taglib-location>
        </taglib>
    
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/x-1-0-rt</taglib-uri>
            <taglib-location>/WEB-INF/tld/x-1_0-rt.tld</taglib-location>
        </taglib>
    </jsp-config>
    

, , TLD JSP, webapp <taglib-uri>, <taglib-location> .

JSP :

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-layout.tld" prefix="layout"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jstl/fn" prefix="fn" %>

, .

+6

BalusC : JAR /WEB-INF/lib taglib JSP. , , - JSP; . Per the Stripes , taglib TLD Stripes :

<%@ taglib prefix="stripes" uri="http://stripes.sourceforge.net/stripes.tld" %>
+1

( , ) , . BalusC , .tld, WEB-INF, . , Struts2, OP (v2.1.8), Apache.

  • , .jar struts-html.tld.

Struts2 struts-html.tld - :

  • struts-tags.tld, META-INF struts2-core-2.1.8.jar Struts, , struts-html.tld Struts1.
  • tiles-jsp.tld, META-INF tiles-jsp-2.0.6.jar , struts-tiles.tld Struts1.
  • TLD, . SiteMesh, .

  1. html, taglib, Struts, JSP. , . , taglib, , .tld .jar 1.2.8.

. :

  • , WEB-INF/lib .jar. Struts2.
  • .jar , TLD META-INF. , , , struts2-core-2.1.8.jar, .
  • When the servlet container loads the TLD, it searches for the element <uri>inside the root element <taglib>and preserves the mapping between that TLD and its URI. Accordingly, this URI is used in your files .jspto refer to TLDs.

In the case, the struts2-core-2.1.8.jarURI is /struts-tags, and so you need to reference it in a file .jsplike this (you can change the attribute prefixto your liking) ...

<%@ taglib uri="/struts-tags" prefix="s" %>

... and then use it, for example this:

<s:form action="HelloWorld">
    (...)
</s:form>
+1
source

All Articles