为何不能添加标签库?(在线)

supjava 2003-04-09 10:31:47
我编写一个简单的引用taglib的jsp程序,但是由于无法找到添加的标签库,所以报错
当我在该应用程序中的web_inf下的web.xml中添加标签库后,当运行后报“无法找到标签库”的错,原来已经添加的标签库自动消失,恢复到原来样子。
请问各位有谁遇到类似情况?如何在web.xml中添加标签库??
非常感谢!!
...全文
64 点赞 收藏 13
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
peacock_king 2003-04-09
在web.xml里部署描述符的位置有非常严格的限制,<taglib></taglib>标记一般都会写在<welcome-file-list></welcome-file-list>后面,如果你把taglib标记写错地方,就会出现如下错误:
Could not parse deployment descriptor(不能解析部署描述符)
回复
supjava 2003-04-09
请问不用web.xml试试如何试?
回复
flashroom 2003-04-09
路过,看看~~~
不用web.xml试试


-------------------------------------------------------------------
我的签名:我做了两天斑竹就被撤了,为什么????
回复
supjava 2003-04-09
up
回复
supjava 2003-04-09
源代码:
**********************************************************************
1)taglibjsp.jsp:

<%@ taglib uri="counters" prefix="util" %>
<html>
<head>
<title>
taglibjsp
</title>
</head>
<body>
This page has been accessed <b><util:counter/></b> times.
</body>
</html>
2)taglibjspBean.java:

package taglibtest;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.http.HttpServletRequest;


public class taglibjspBean extends TagSupport {
private int count = 0;
private File file = null;
public int doStartTag() throws JspException {
try
{
checkFile();
readCount();
pageContext.getOut().print(++count);
}
catch (java.io.IOException ex)
{
throw new JspException(ex.getMessage());
}
return SKIP_BODY;
}
public int doEndTag() throws JspException {
saveCount();
return EVAL_PAGE;
}
private void checkFile() throws JspException,IOException {
if (file == null) {
file = new File(getCounterFilename());
count = 0;
}
if (!file.exists()) {
file.createNewFile();
saveCount();
}
}
private String getCounterFilename() {
HttpServletRequest req = (HttpServletRequest)pageContext.getRequest();
String servletPath = req.getServletPath();
String realPath = pageContext.getServletContext().getRealPath(servletPath);

return realPath + ".Counter";
}
private void saveCount() throws JspException {
try {
FileWriter writer = new FileWriter(file);
writer.write(count);
writer.close();
}
catch (Exception ex) {
throw new JspException(ex.getMessage());
}
}
private void readCount() throws JspException {
try {
FileReader reader = new FileReader(file);
count = reader.read();
reader.close();
}
catch (Exception ex) {
throw new JspException(ex.getMessage());
}
}
}

3)counter.tld:

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">

<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>Tag library</shortname>
<info>this is test tag library!</info>

<tag>
<name>counter</name>
<tagclass>taglibtest.taglibjspBean</tagclass>
<bodycontent>empty</bodycontent>
</tag>

</taglib>

********************************************************************
当编译时出现以下错误:
1)"taglibjsp.jsp": Could not parse deployment descriptor: java.io.IOException: cannot resolve 'counters' into a valid tag library at line 1
2)"taglibjsp.jsp": weblogic.servlet.jsp.JspException: (line 1): Could not parse deployment descriptor: java.io.IOException: cannot resolve 'counters' into a valid tag library
或者是括号里的错误:
(“Could not parse deployment descriptor: java.io.IOException: cannot resolve 'counters' into a valid tag library。”
probably occurred due to an error in /taglibjsp.jsp line 1:<%@ taglib uri="counters" prefix="util" %> )

请问各位大侠如何修改??非常感谢!!!
回复
whodsow 2003-04-09
贴出源文件来。
回复
supjava 2003-04-09
谢谢楼上!
但我就是用tld文件,最后还的要把该tld信息写在web.xml文件中啊!
楼上有什么更好的办法??
回复
moumouren 2003-04-09
建议用tld文件
回复
supjava 2003-04-09
myself up!
回复
zhxx 2003-04-09
我碰到过jboos里正常
weblogic就出现这种情况
回复
sgdb 2003-04-09
sorry

<%@ taglib uri="/counter.tld" prefix="util" %>
<html>
<head>
<title>
taglibjsp
</title>
</head>
<body>
This page has been accessed <b><util:counter/></b> times.
</body>
</html>

回复
sgdb 2003-04-09
taglibjsp.jsp:

<%@ taglib uri="/counters.tld" prefix="util" %>
<html>
<head>
<title>
taglibjsp
</title>
</head>
<body>
This page has been accessed <b><util:counter/></b> times.
</body>
</html>
回复
supjava 2003-04-09
up
回复
相关推荐
基于java的企业人事管理系统设计--软件工程课程设计(含源码与论文设计).rar 1 引言 4 1.1 课程设计目标 4 1.2 编程工具(编程环境)介绍 4 1.3 实施时间及主要实施步骤 4 2 需求分析 5 3 系统总体设计 6 4 数据设计 6 5 主要功能模块的设计与实现 10 5.1 功能模块1详细设计(综合查询员工信息)..........................................................10 5.1.1 详细设计.......................................................................................................10 5.1.2 算法流程........................................................................................................15 5.1.3 界面设计及测试结果.....................................................................................15 6 调试分析 15 7 用户手册 16 8 测试结果 17 8.1 员工信息的添加...................................................................................................17 8.2 员工信息的修改...................................................................................................17 8.3 员工信息的删除...................................................................................................18 8.4 员工信息的综合查询...........................................................................................18 8.5 员工信息按性别统计的结果................................................................................19 8.6 员工信息按状态统计的结果...............................................................................19 8.7 员工信息按职称统计的结果................................................................................20 9 结论 20 10 参考文献 20
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2003-04-09 10:31
社区公告
暂无公告