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. HTML5_拖放

    拖放(Drag 和 drop)是 HTML5 标准的组成部分.拖放是一种常见的特性,即抓取对象以后拖到另一个位置.在 HTML5 中,拖放是标准的一部分,任何元素都能够拖放. 支持的浏览器:Inter ...

  2. CSS处理溢出

    如果内容超过的区块的大小,内容就会溢出,可以使用下面的方法控制溢出 overflow visible 不剪切内容也不添加滚动条 auto 在必需时对象内容才会被裁切或显示滚动条 hidden 不显示超 ...

  3. 记一次高级java工程师职位的面试

    阿里在业内做java方面的有关开发可谓是一流的.它给我的第一印象,就是办事效率很高. 周日简历发过去,周一电话就打过来了,接到电话后,面试官很客气,问现在方面吗,我说现在在上班,有点忙,然后和面试官约 ...

  4. Struts2+Uploadify文件上传使用详解

    Uploadify是JQuery的一个上传插件,实现的效果非常不错,带进度显示.不过官方提供的实例是php版本的,本文将详细介绍Uploadify在java中的使用,您也可以点击下面的链接进行演示或下 ...

  5. codeforces 431 B Shower Line【暴力】

    题意:给出五个人的编号,分别为 1 2 3 4 5,他们在排队, 最开始的时候,1和2可以交谈,3和4可以交谈 然后1走了之后,2和3交谈,4和5可以交谈 2走了之后,3和4可以交谈, 3走了之后,4 ...

  6. UVa 247 Calling Circles【传递闭包】

    题意:给出n个人的m次电话,问最后构成多少个环,找出所有的环 自己想的是:用map来储存人名,每个人名映射成一个数字编号,再用并查集,求出有多少块连通块,输出 可是map不熟,写不出来,而且用并查集输 ...

  7. 20160201.CCPP体系详解(0011天)

    内容概要:C语言基本数据类型及运算题库(含答案) 第二章 基本数据类型及运算 一.选择题 1. 若以下选项中的变量已正确定义,则正确的赋值语句是[C]. A) x1=26.8%3; B) 1+2=x2 ...

  8. 【C#学习笔记】从粘贴板复制文本

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  9. Android下实现tab页个人比较推崇的方法

    使用fragment实现tab页的效果: 三个页面是单独的三个Fragment 主Activity的实现: package com.hsx.tab; import android.os.Bundle; ...

  10. Python使用os.listdir()函数来得目录内容的介绍

    Python编程语言是计算机语言中常用的语言,以下的文章就是介绍在Python编程语言中使用os.listdir()函数来获得目录中的相关内容的介绍,如果你对其相关的实际操作有兴趣的话,你就可以观看以 ...