使用自定义标签出错(50分)

  • 主题发起人 主题发起人 游委宾
  • 开始时间 开始时间

游委宾

Unregistered / Unconfirmed
GUEST, unregistred user!
出错信息为:
Parsing of JSP File '/tagtest.jsp' failed:
--------------------------------------------------------------------------------
/tagtest.jsp(1): Error in using tag library uri='taglib.tld' prefix='title':
cannot find tag class: 'Title'
probably occurred due to an error in /tagtest.jsp line 1:
<%@ taglib uri="taglib.tld" prefix="title" %>
我已经写了Title.java文件,
下面是taglib.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>titleTag</shortname>
<info>
tag test
</info>

<tag>
<name>titleTag</name>
<tagclass>Title</tagclass>
<bodycontent>JSP</bodycontent>
<info>
Title Tag Test
</info>
</tag>
</taglib>
 
大小写?
 
那个类的名称也叫做“Title”
 
我把所有的源码贴出来吧。
tagtest.jsp:
<%@ taglib uri="taglib.tld" prefix="myTagLib" %>
<html>
<head>
<myTagLib:Title/>
</head>
<body>
hello jsp
</body>
</html>
taglib.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>myTagLib</shortname>
<info>
tag test
</info>
<tag>
<name>Title</name>
<tagclass>Title</tagclass>
<bodycontent>JSP</bodycontent>
<info>
Title Tag Test
</info>
</tag>
</taglib>
Title.java:
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
//import java.io.IOException;
public class Title extends TagSupport
{
public intdo
StartTag()
{
try
{
pageContext.getOut().println("<title>Title Tag Test</title>");
}
catch(Exception e)
{
return 0;
}
return EVAL_BODY_INCLUDE;
}
}

 
这个与你的jsp服务器及你是如何发布你的应用的有关。
我所用的测试环境是:Jbuilder7+Tomcat4
tagtest.jsp文件如下:
<%@ taglib uri="/WEB-INF/taglib.tld" prefix="myTagLib" %>
<html>
<head>
<myTagLib:Title/>
</head>
<body>
hello jsp
</body>
</html>
taglib.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>myTagLib</shortname>
<info>
tag test
</info>
<tag>
<name>Title</name>
<tagclass>untitled1.Title</tagclass>
<bodycontent>JSP</bodycontent>
<info>
Title Tag Test
</info>
</tag>
</taglib>
如上面的代码所示taglib.tld在WEB-INF目录中,Title.class在WEB-INF/classes/untitled1
目录中。测试通过。你的问题就是找不到Title.class文件。
 
我是没有.class文件,只有.java文件,然道要先编译?
 
没错,要先编译。好像有些服务器可以设置为自动编译。
 
kehua:tld文件和class文件不一定要放在web-inf目录下吧。
我现在编译好了,运行时出一堆的错。
我用的是WebLogic.

Compilation of 'D:/forum/WEB-INF/_tmp_war_taxi_taxi_forum/jsp_servlet/_tagtest.java' failed:
--------------------------------------------------------------------------------
D:/forum/WEB-INF/_tmp_war_taxi_taxi_forum/jsp_servlet/_tagtest.java:81: cannot resolve symbol
(No more information available, probably caused by another error)
D:/forum/WEB-INF/_tmp_war_taxi_taxi_forum/jsp_servlet/_tagtest.java:100: cannot resolve symbol
probably occurred due to an error in /tagtest.jsp line 5:
<myTagLib:Title/>
D:/forum/WEB-INF/_tmp_war_taxi_taxi_forum/jsp_servlet/_tagtest.java uses or overrides a deprecated API.
--------------------------------------------------------------------------------
Full compiler error(s):
D:/forum/WEB-INF/_tmp_war_taxi_taxi_forum/jsp_servlet/_tagtest.java:81: cannot resolve symbol
symbol : class Title
location: class jsp_servlet._tagtest
Title _myTagLib_Title0 = null;
^
D:/forum/WEB-INF/_tmp_war_taxi_taxi_forum/jsp_servlet/_tagtest.java:100: cannot resolve symbol
symbol : class Title
location: class jsp_servlet._tagtest
if (_myTagLib_Title0 == null) _myTagLib_Title0 = new Title();
//[ /tagtest.jsp;
Line: 5]
^
Note: D:/forum/WEB-INF/_tmp_war_taxi_taxi_forum/jsp_servlet/_tagtest.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
2 errors
 
成功啦。
 
接受答案了.
 
后退
顶部