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

supjava 2003-04-09 10:31:47
我编写一个简单的引用taglib的jsp程序,但是由于无法找到添加的标签库,所以报错
当我在该应用程序中的web_inf下的web.xml中添加标签库后,当运行后报“无法找到标签库”的错,原来已经添加的标签库自动消失,恢复到原来样子。
请问各位有谁遇到类似情况?如何在web.xml中添加标签库??
非常感谢!!
...全文
112 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
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

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧