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.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的更多相关文章
- Liferay JSP Tag Libraries介绍
Liferay自带了很多标签库,这极大地提高了开发Liferay项目的效率. 下面让我们一起来探索吧. 什么是标签库? 什么是JSP标签? 什么是JSTL? 标签库由下面这几部分组成: Tag Lib ...
- Struts tag -s
1,if/elseif/else标签 <s:set value="19"/> <s:if test="%{#age > 60}"> ...
- Struts Hello World Example
In this tutorial we show you how to develop a hello world web application using classic Struts 1.3 f ...
- Struts 2 Learning
目录 . J2EE简介 . JAVA EE应用的分层模型 . 搭建Struts2 Demo应用 . struts2流程 . struts2的常规配置 . 实现Action . 配置Action . 配 ...
- Struts学习总结-04 上传文件
1. upload.jsp <%@ page language="java" import="java.util.*" pageEncoding=&quo ...
- Struts学习总结-02 类型转换
一 类型转换 input.jsp <%@ page language="java" import="java.util.*" pageEncoding=& ...
- struts.properties配置详解
Struts 2框架有两个核心配置文件,其中struts.xml文件主要负责管理应用中的Action映射,以及该Action包含的Result定义等.除此之外,Struts 2框架还包含 st ...
- Struts.xml讲解
解决在断网环境下,配置文件无提示的问题我们可以看到Struts.xml在断网的情况下,前面有一个叹号,这时,我们按alt+/ 没有提示,这是因为” http://struts.apache.org/d ...
- struts.properties的参数描述
A.2.1 概述 如果我们希望覆盖在default.properties文件里面定义的默认配置,那就可以定义struts.properties文件,在里面设置我们需要的值,当然现在也可以在struts ...
随机推荐
- Android 实现布局动态加载
Android 动态加载布局 通过使用LayoutInflater 每次点击按钮时候去读取布局文件,然后找到布局文件里面的各个VIEW 操作完VIEW 后加载进我们setContentView 方面里 ...
- blade全集
http://daylerees.com/codebright/blade
- 使用git submodule管理一个需要多个分立开发或者第三方repo的项目
在项目开发中,特别是web前端开发中,有非常多的开源第三方library,我们希望引用他们,同时也希望能够方便地保持这些第三方 开源repo的更新.另外一方面如果我们自己在开发一个网站的项目,这个项目 ...
- Android 最火的快速开发框架XUtils
参考:http://www.oschina.net/p/xutils 项目git地址https://github.com/wyouflf/xUtils 目录(?)[-] 最近搜了一些框架供初学者学习比 ...
- VS2015新功能
今天有幸参加了微软的 Visual Studio Dev Day,趁还没有忘记今天的学习内容. 先把这些内容记录下来,如果有其他人也参加此次交流活动,请补充完善. VS2015新功能 1,Roslyn ...
- hdu 4647 Another Graph Game
题意: 有N个点,M条边. 点有权值, 边有权值. Alice, Bob 分别选点. 如果一条边的两个顶点被同一个人选了, 那么能获得该权值.问 Alice - Bob? 链接:http://acm. ...
- Android中的Drawable资源
在Android应用中,常常会用到Drawable资源,比如图片资源等,在Android开发中我们是用Drawable类来Drawable类型资源的. Drawable资源一般存储在应用程序目录的\r ...
- smarty分页模板(用模板语法写分页)
分页是一个我们经常要用到的.比较基本的小功能,你可以通过定义一个方法或类来对它进行封装.重用.而本文则是通过利用smarty独有的语法,以模版的方式进行封装,从而达到同样的目的. 下面开始具体实现步骤 ...
- POJ 1201 Intervals (差分约束,最短路)
题意: 有一个集合Z,其元素都是整整数,但是数量未知.现有n个约束,形如 [a,b]=c 表示整数区间[a,b]中有c个元素在Z中出现.问集合Z最小可能含多少个元素? 思路: 对于所给的区间 cnt[ ...
- python numpy array 的一些问题
1 将list转换成array 如果list的嵌套数组是不规整的,如 a = [[1,2], [3,4,5]] 则a = numpy.array(a)之后 a的type是ndarray,但是a中得元素 ...