zoukankan      html  css  js  c++  java
  • Configure the Struts Tag Libraries

    In Struts framework, you always need to configure the Struts tag libraries in order to access it in view page (JSP). There are two ways to configure it.

    1. Strut Tag Libraries Manual Configuration

    The manual configuration is the old and classic way, used in Struts version <= 1.1 and Servlet < 2.3 container. Download all the Struts dependencies, make sure the following “tld” files are copy to WEB-INF folder, you can find these files in the downloaded Struts library.

    • struts-bean.tld
    • struts-html.tld
    • struts-logic.tld
    • struts-tiles.tld

    Declare the taglib uri in web.xml

    web.xml

    ...
    <taglib>
         <taglib-uri>
    	  http://struts.apache.org/tags-bean
         </taglib-uri>
         <taglib-location>
    	  /WEB-INF/struts-bean.tld
         </taglib-location>
    </taglib>
    <taglib>
         <taglib-uri>
    	  http://struts.apache.org/tags-html
         </taglib-uri>
         <taglib-location>
    	  /WEB-INF/struts-html.tld
         </taglib-location>
    </taglib>
    <taglib>
         <taglib-uri>
    	  http://struts.apache.org/tags-logic
         </taglib-uri>
         <taglib-location>
    	  /WEB-INF/struts-logic.tld
         </taglib-location>
    </taglib>
    <taglib>
         <taglib-uri>
    	  http://struts.apache.org/tags-tiles
         </taglib-uri>
         <taglib-location>
    	  /WEB-INF/struts-tiles.tld
         </taglib-location>
    </taglib>
    <taglib>
         <taglib-uri>
    	  http://struts.apache.org/tags-nested
         </taglib-uri>
         <taglib-location>
    	  /WEB-INF/struts-nested.tld
         </taglib-location>
    </taglib>
    ...
    
    

    Now you can access it in JSP page. The JSP’s @taglib uri have to match with web.xml <taglib-uri>

    <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
    <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
    <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
    <%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
    

    Actually, you can define your own taglib uri name, for example

    web.xml

    ...
    <taglib>
         <taglib-uri>
    	  customer-anything/tags-bean
         </taglib-uri>
         <taglib-location>
    	  /WEB-INF/struts-bean.tld
         </taglib-location>
    </taglib>
    ...
    

    Then access it via your custom taglib uri name.

    <%@ taglib uri="customer-anything/tags-bean" prefix="bean" %>
    

    2. Strut Tag Libraries Automatic Configuration

    This is the easy way, and used in Struts version 1.2, 1.3 and Servlet 2.3/2.4 container only. You do not need to define the “tlds” details in web.xml anymore, just include the struts-taglib.jar in your project classpath or copy it to WEB-INF/lib folder.

    All the “tld” details are define inside the “struts-taglib.jarMETA-INF ld” folder. During deployment, the struts-bean.tld, struts-html.tld, struts-logic.tld and struts-tiles.tld will deploy automatically. However, you can access it via the following “pre-fixed uri” name only. In this method, you are not allow to change the “taglib uri” name.

    <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
    <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
    <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
    <%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
    ``
    ##FAQ
    
    Q : Look like the “taglib uri” is pointing to Apache website, how about the client has NO internet access?
    A : The taglib uri is define in “`struts-taglib.jarMETA-INF	ld`” folder, it’s just a project uri name, not pointing to Apache website, you still can access it even in no internet access environment.
    
    Q : Can the manual configuration work in latest Struts 1.2 or 1.3?
    A : Yes, Struts is backward compatible, the old way is still support in Struts 1.2 and 1.3.
    
    Q : Which method is the best?
    A : It’s depend, the automatic configuration is only worked in Servlet 2.3/2.4 container. If you are allow to choose, please go to the automatic method, why you want to copy the tld files manually?
  • 相关阅读:
    简单跟跟spring源码
    java.lang.UnsupportedOperationException mybatis
    通过自定义注解校验后台接口请求参数
    java的修饰符 public --> protected -->default --> private
    Ubuntu安装google-chrome
    git设置core.autocrlf
    时钟时间,系统cpu时间,用户cpu时间
    推荐-Everything搜索工具
    Ubuntu no such file or directory
    centos安装docker
  • 原文地址:https://www.cnblogs.com/ghgyj/p/4766252.html
Copyright © 2011-2022 走看看