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.jar\META-INF\tld” 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.jar\META-INF\tld`” 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?

Configure the Struts Tag Libraries的更多相关文章

  1. Liferay JSP Tag Libraries介绍

    Liferay自带了很多标签库,这极大地提高了开发Liferay项目的效率. 下面让我们一起来探索吧. 什么是标签库? 什么是JSP标签? 什么是JSTL? 标签库由下面这几部分组成: Tag Lib ...

  2. Struts tag -s

    1,if/elseif/else标签 <s:set value="19"/> <s:if test="%{#age > 60}"> ...

  3. Struts Hello World Example

    In this tutorial we show you how to develop a hello world web application using classic Struts 1.3 f ...

  4. Struts 2 Learning

    目录 . J2EE简介 . JAVA EE应用的分层模型 . 搭建Struts2 Demo应用 . struts2流程 . struts2的常规配置 . 实现Action . 配置Action . 配 ...

  5. Struts学习总结-04 上传文件

    1. upload.jsp <%@ page language="java" import="java.util.*" pageEncoding=&quo ...

  6. Struts学习总结-02 类型转换

    一 类型转换 input.jsp <%@ page language="java" import="java.util.*" pageEncoding=& ...

  7. struts.properties配置详解

    Struts 2框架有两个核心配置文件,其中struts.xml文件主要负责管理应用中的Action映射,以及该Action包含的Result定义等.除此之外,Struts 2框架还包含     st ...

  8. Struts.xml讲解

    解决在断网环境下,配置文件无提示的问题我们可以看到Struts.xml在断网的情况下,前面有一个叹号,这时,我们按alt+/ 没有提示,这是因为” http://struts.apache.org/d ...

  9. struts.properties的参数描述

    A.2.1 概述 如果我们希望覆盖在default.properties文件里面定义的默认配置,那就可以定义struts.properties文件,在里面设置我们需要的值,当然现在也可以在struts ...

随机推荐

  1. core--线程池

    对于服务器-客户端这种架构的软件,通常客户端的数据来自于服务器,如何让一个服务器进程,来满足多个客户端程序的数据请求?一种简单的方法就是,每当一个客户请求来领,服务器就为该客户端创建一个线程.当有10 ...

  2. HDU 1838 Chessboard

    dp[i][j]表示以(i,j)为右下角所含棋盘的最大规模, 如果 s[i][j] == s[i-1][j-1] && s[i][j] != s[i-1][j] && ...

  3. Oracle® Database Patch 19121551 - Database Patch Set Update 11.2.0.4.4 (Includes CPUOct2014) - 傲游云浏览

    Skip Headers Oracle® Database Patch 19121551 - Database Patch Set Update 11.2.0.4.4 (Includes CPUOct ...

  4. bdyyservice.exe 系统错误

    现象:开机出现 bdyyservice.exe 系统错误,说: 计算机中丢失log_report.dll 原因:安装百度影音,卸载后出现的问题 解决方法: 所有程序 -> 附件 -> 命令 ...

  5. Android failed creating starting window

    /***************************************************************************** * Android failed crea ...

  6. ecshop 调用指定分类的推荐,热卖,新品

    未测试 1.includes/lib_goods.php文件.把SQL语句改一下,与category表关联即可 将 $sql = 'SELECT g.goods_id,g.goods_name, g. ...

  7. jQuery.validate API

  8. php 系统命令执行函数

    (转载)作者:海底苍鹰地址:http://blog.51yip.com/php/1064.html 1,exec函数 <?php $test = "ls /tmp/test" ...

  9. bootstrap-datetimepicker在经过GC(Google Closure Compiler)压缩后无法使用的解决方案

    将压缩级别由simple改成whitespace 问题就是这样之后压缩后的文件大了很多 <?xml version="1.0"?> <project name=& ...

  10. python定义影像投影

    import os import arcgisscripting gp=arcgisscripting.create() coordsys=r"C:\Winx86\ArcGIS\Coordi ...