Struts - Taglib directive in a JSP page for .tld provided by Struts

前端 未结 3 1944
鱼传尺愫
鱼传尺愫 2021-01-01 00:38

I am developing a Struts based application. I am new to Struts. I want to use html tags , specified in a taglib directory provided by Struts<

3条回答
  •  囚心锁ツ
    2021-01-01 01:15

    I'm using Struts 1.3.10 for this illustration:

    1. Download the latest struts library here (http://struts.apache.org/download.cgi#struts1310). Remember, the Full Distribution is that what you have to download as it contains a war file with the Struts TLD's.
    2. On your web application, copy all the lib in the archive file you downloaded to your /WEB-INF/lib folder.
    3. For JSTL libraries (which works well with struts) go here (http://java.sun.com/products/jsp/jstl/)
    4. Once you have your Struts TLD's and JSTL Tld's, put them under the /WEB-INF/tld/ folder (it must be situated in the /WEB-INF/ folder).
    5. On web.xml add the following stuff (under the element)

        
          
              /WEB-INF/struts-bean.tld
              /WEB-INF/tld/struts-bean.tld
          
          
              /WEB-INF/struts-html.tld
              /WEB-INF/tld/struts-html.tld
          
          
              /WEB-INF/struts-logic.tld
              /WEB-INF/tld/struts-logic.tld
          
          
              /WEB-INF/struts-nested.tld
              /WEB-INF/tld/struts-nested.tld
          
          
              /WEB-INF/struts-tiles.tld
              /WEB-INF/tld/struts-tiles.tld
          
          
              /WEB-INF/sslext.tld
              /WEB-INF/tld/sslext.tld
          
          
              /WEB-INF/struts-layout.tld
              /WEB-INF/tld/struts-layout.tld
          
      
          
          
              http://java.sun.com/jstl/fn
              /WEB-INF/tld/fn.tld
          
      
          
              http://java.sun.com/jstl/fmt
              /WEB-INF/tld/fmt.tld
          
      
          
              http://java.sun.com/jstl/fmt-1-0
              /WEB-INF/tld/fmt-1_0.tld
          
      
          
              http://java.sun.com/jstl/fmt-rt
              /WEB-INF/tld/fmt-rt.tld
          
      
          
              http://java.sun.com/jstl/fmt-1-0-rt
              /WEB-INF/tld/fmt-1_0-rt.tld
          
      
          
              http://java.sun.com/jstl/core
              /WEB-INF/tld/c.tld
          
      
          
              http://java.sun.com/jstl/core-1-0
              /WEB-INF/tld/c-1_0.tld
          
      
          
              http://java.sun.com/jstl/core-rt
              /WEB-INF/tld/c-rt.tld
          
      
          
              http://java.sun.com/jstl/core-1-0-rt
              /WEB-INF/tld/c-1_0-rt.tld
          
      
          
              http://java.sun.com/jstl/sql
              /WEB-INF/tld/sql.tld
          
      
          
              http://java.sun.com/jstl/sql-1-0
              /WEB-INF/tld/sql-1_0.tld
          
      
          
              http://java.sun.com/jstl/sql-rt
              /WEB-INF/tld/sql-rt.tld
          
      
          
              http://java.sun.com/jstl/sql-1-0-rt
              /WEB-INF/tld/sql-1_0-rt.tld
          
      
          
              http://java.sun.com/jstl/x
              /WEB-INF/tld/x.tld
          
      
          
              http://java.sun.com/jstl/x-1-0
              /WEB-INF/tld/x-1_0.tld
          
      
          
              http://java.sun.com/jstl/x-rt
              /WEB-INF/tld/x-rt.tld
          
      
          
              http://java.sun.com/jstl/x-1-0-rt
              /WEB-INF/tld/x-1_0-rt.tld
          
      
      

    This tells that once you call your TLD from the JSP, your webapp will look for the matching then look for it's location on and find relevant class to call.

    On your JSP, now you can do this:

    <%@ 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" %>
    

    Hope this helps.

提交回复
热议问题