File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Custom Tags Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Custom Tags" Watch "Custom Tags" New topic
Author

Custom Tags

Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Hi all,
I am having probs with running the JSP with custom tags.It just prints Hello Mary on the browser.
I think am wrong in putting the files in the appropriate directories.
So pl help me as to where I have to put tld files,class files and the JSP files.Am using Weblogic 5.1 to run the JSPs.
The .tld files is as follows

<?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-jsptaglibrbay_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion> <jspversion>1.1</jspversion>
<shortname>mt</shortname>
<info> My first tag</info>
<tag>
<name> helloworld</name>
<tagClass>weblogic.taglib.sample.HelloWorldTag</tagClass>
<bodycontent>empty</bodycontent>
<info> A Hello World Tag</info>
</tag>
</taglib>
---------------------------------------------------------------
This is the JSp file

<%@ taglib uri ="/weblogic/taglib/sample" prefix ="sample" %>
<html>
<head>
<title> HelloWorld></title>
</head>
<body bgcolor = #FFFFFF">
<hr>
<sample:helloworld/>
<hr>
</body>
</html>
------------------------------------------------------------
This is the Java file

package weblogic.taglib.sample;

import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

public class HelloWorldTag implements Tag
{
private PageContext pageContext;
private Tag parent;

public HelloWorldTag()
{
super();
}
public int doStartTag() throws javax.servlet.jsp.JspTagException
{
return SKIP_BODY;
}
public int doEndTag() throws javax.servlet.jsp.JspTagException
{
try
{
pageContext.getOut().write("Hello Mary");
}
catch(java.io.IOException e)
{
throw new JspTagException("IOError:" +e.getMessage());
}
return EVAL_PAGE;
}
public void release()
{
}
public void setPageContext(final javax.servlet.jsp.PageContext pageContext)
{
this.pageContext = pageContext;
}
public void setParent(final javax.servlet.jsp.tagext.Tag parent)
{
this.parent = parent;
}
public javax.servlet.jsp.tagext.Tag getParent()
{
return parent;
}
}
------------------------------------------------------------
This line of code I have put it in properties file

weblogic.httpd.webApp.sample=/weblogic/examples/jsp/tagext/sample

Pl reply
Thanx in advance
Cynthia Yao
Ranch Hand

Joined: Nov 06, 2000
Posts: 92
You do not need to register taglib file as servlet, those are just classes files, as long as you put there where all the other classes or bean files are located, it is fine.
However, the taglib uri should point to where the tld file is. Did you get the error that it can not load the taglib class?
Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Hi,
I got the error like this on the weblogic server

Sun Jan 14 11:24:10 GMT+05:30 2001:<E> <ServletContext-General> Cannot find reso
urce '/weblogic/taglib/sample' in document root 'D:\weblogic\myserver\public_htm
l'
Sun Jan 14 11:24:10 GMT+05:30 2001:<E> <ServletContext-General> Servlet failed w
ith Exception
javax.servlet.ServletException: compilation of /sample/sample.jsp failed: weblog
ic.utils.ParsingException: nested IOException: java.io.IOException: cannot resol
ve '/weblogic/taglib/sample' into a valid tag library
at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:182)
at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.
java:164)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:99)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:123)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletCon
textImpl.java:742)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletCon
textImpl.java:686)
at weblogic.servlet.internal.ServletContextManager.invokeServlet(Servlet
ContextManager.java:247)
at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.jav
a:361)
at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:261)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java, Compiled Code)
Sun Jan 14 11:24:10 GMT+05:30 2001:<E> <ServletContext-General> root cause of Se
rvletException
weblogic.utils.ParsingException: nested IOException: java.io.IOException: cannot
resolve '/weblogic/taglib/sample' into a valid tag library
at weblogic.servlet.jsp.JspLexer.parse(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspParser.doit(JspParser.java, Compiled Code)
at weblogic.servlet.jsp.JspParser.parse(JspParser.java:109)
at weblogic.servlet.jsp.Jsp2Java.outputs(Jsp2Java.java:97)
at weblogic.utils.compiler.CodeGenerator.generate(CodeGenerator.java, Co
mpiled Code)
at weblogic.servlet.jsp.JspStub.compilePage(JspStub.java, Compiled Code)
at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:174)
at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.
java:164)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:99)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:123)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletCon
textImpl.java:742)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletCon
textImpl.java:686)
at weblogic.servlet.internal.ServletContextManager.invokeServlet(Servlet
ContextManager.java:247)
at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.jav
a:361)
at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:261)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java, Compiled Code)
Sun Jan 14 11:24:13 GMT+05:30 2001:<I> <ServletContext-General> servletimages: i
nit

Pl look if u can figure out something from this
Thanx
Cynthia Yao
Ranch Hand

Joined: Nov 06, 2000
Posts: 92
Look at the error message proved my point --
<%@ taglib uri ="/weblogic/taglib/sample" prefix ="sample" %>
this line the taglib uri should point to where the "tld" file is, not the class file. For example, this is in my file:
<%@ taglib uri="/WEB-INF/tlds/cosmo.tld" prefix="cosmo" %>

Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Hi Cynathia,
I tried your method and its giving an error as shown below on the browser
Parsing of JSP File '/sample/sample.jsp' failed:
--------------------------------------------------------------------------------
/sample/sample.jsp(1): Could not parse deployment descriptor: org.xml.sax.SAXParseException: Could not parse: taglib starting at line 1
probably occurred due to an error in /sample/sample.jsp line 1:
<%@ taglib uri ="/WEB-INF/taglib.tld" prefix ="sample" %>
===========================================
this is my eidted JSP file
==================================

<%@ taglib uri ="WEB-INF/taglib.tld" prefix ="mt" %>
<html>
<head>
<title> HelloWorld></title>
</head>
<body bgcolor = #FFFFFF">
<hr>
<mt:helloworld/>
<hr>
</body>
</html>
=======================================
so pl help me where am going wrong
[This message has been edited by Mary, Cole (edited February 14, 2001).]
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
It is the same error message I got -- could not parse deployment descriptor. I seeked a couple hours earlier. Nobody has responded to my SOS.
Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Hi all,
PL help me to solve my problem
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Mary:
I ran into the same problem as you did a couple of days ago. I have talked to several people.
Let us try this together:
because in the library file the statement in the <tagclass> tag showing the HelloWorldTag.java is in the sample subdirectory. Therefore, go to the directory hierarchy one level higher than the sample subdirectory and type
c:\..\OneLevelHigherSubdirectory>javac sample\HelloWorldTag.java
when complile the HelloWorldTag.java
Please let me know if it works. My e-mail address is
jiapei_jen@yahoo.com
if you want to contact me directly.
Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Hi Jen,
I tried it but without any success.
Lemme know if U have had any sucsess
Pl relpy
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Mary,
I am currently rushing to finish a project. I will get back to you then.
I want to work out the problem which we both ran into. I mean it.
Cynthia Yao
Ranch Hand

Joined: Nov 06, 2000
Posts: 92
When I check it more carefully, you missed / in the taglib declaration.
<%@ taglib uri="<B>/</B>WEB-INF/whatever.tld" prefix="cosmo" %>
When you run jsp in weblogic, look at the log file, you will see all the process. Check to see whether the server is try to find the tld file and load it successfully.
Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Hi Cynthia Yao,
I tried it giving "/web-inf/taglib.tld"
its giving error on the server like this---
=============================================================
Wed Feb 21 11:42:49 GMT+05:30 2001:<E> <ServletContext-sample> Cannot find resource '/WEB-INF/web-inf/taglib.tld' in document root 'D:\weblogic\examples\jsp\tagext\sample'
Wed Feb 21 11:42:49 GMT+05:30 2001:<E> <ServletContext-sample> failure pre-compiling JSP's
weblogic.servlet.jsp.JspException: (line 1): Could not parse deployment descriptor: org.xml.sax.SAXParseException: Could not parse: taglib starting at line 1
at weblogic.servlet.jsp.JspLexer.jspException(JspLexer.java:574)
at weblogic.servlet.jsp.JspLexer.mTAGLIB_DIRECTIVE_BODY(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspLexer.mTAGLIB_DIRECTIVE(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspLexer.mDIRECTIVE(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspLexer.mSTANDARD_THING(JspLexer.java:1636)
at weblogic.servlet.jsp.JspLexer.mTOKEN(JspLexer.java:1477)
at weblogic.servlet.jsp.JspLexer.nextToken(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspLexer.parse(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspParser.doit(JspParser.java, Compiled Code)
at weblogic.servlet.jsp.JspParser.parse(JspParser.java:109)
at weblogic.servlet.jsp.Jsp2Java.outputs(Jsp2Java.java:97)
at weblogic.utils.compiler.CodeGenerator.generate(CodeGenerator.java, Compiled Code)
at weblogic.servlet.jsp.Precompiler.compileOne(Precompiler.java:116)
at weblogic.servlet.jsp.Precompiler.compile(Precompiler.java, Compiled Code)
at weblogic.servlet.internal.ServletContextImpl.precompileJSPs(ServletContextImpl.java:1166)
at weblogic.servlet.internal.dd.DescriptorLoader.createServletContext(DescriptorLoader.java, Compiled Code)
at weblogic.t3.srvr.HttpServer.loadWARContext(HttpServer.java:666)
at weblogic.t3.srvr.HttpServer.initServletContexts(HttpServer.java, Compiled Code)
at weblogic.t3.srvr.HttpServer.start(HttpServer.java:442)
at weblogic.t3.srvr.T3Srvr.start(T3Srvr.java, Compiled Code)
at weblogic.t3.srvr.T3Srvr.main(T3Srvr.java:825)
at java.lang.reflect.Method.invoke(Native Method)
at weblogic.Server.startServerDynamically(Server.java:99)
at weblogic.Server.main(Server.java:65)
at weblogic.Server.main(Server.java:55)
at weblogic.NTServiceHelper.run(NTServiceHelper.java:19)
at java.lang.Thread.run(Thread.java:479)
Wed Feb 21 11:42:49 GMT+05:30 2001:<E> <HTTP> Error creating servlet context for Web application '/weblogic/examples/jsp/tagext/sample'
weblogic.servlet.jsp.JspException: (line 1): Could not parse deployment descriptor: org.xml.sax.SAXParseException: Could not parse: taglib starting at line 1
at weblogic.servlet.jsp.JspLexer.jspException(JspLexer.java:574)
at weblogic.servlet.jsp.JspLexer.mTAGLIB_DIRECTIVE_BODY(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspLexer.mTAGLIB_DIRECTIVE(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspLexer.mDIRECTIVE(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspLexer.mSTANDARD_THING(JspLexer.java:1636)
at weblogic.servlet.jsp.JspLexer.mTOKEN(JspLexer.java:1477)
at weblogic.servlet.jsp.JspLexer.nextToken(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspLexer.parse(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspParser.doit(JspParser.java, Compiled Code)
at weblogic.servlet.jsp.JspParser.parse(JspParser.java:109)
at weblogic.servlet.jsp.Jsp2Java.outputs(Jsp2Java.java:97)
at weblogic.utils.compiler.CodeGenerator.generate(CodeGenerator.java, Compiled Code)
at weblogic.servlet.jsp.Precompiler.compileOne(Precompiler.java:116)
at weblogic.servlet.jsp.Precompiler.compile(Precompiler.java, Compiled Code)
at weblogic.servlet.internal.ServletContextImpl.precompileJSPs(ServletContextImpl.java:1166)
at weblogic.servlet.internal.dd.DescriptorLoader.createServletContext(DescriptorLoader.java, Compiled Code)
at weblogic.t3.srvr.HttpServer.loadWARContext(HttpServer.java:666)
at weblogic.t3.srvr.HttpServer.initServletContexts(HttpServer.java, Compiled Code)
at weblogic.t3.srvr.HttpServer.start(HttpServer.java:442)
at weblogic.t3.srvr.T3Srvr.start(T3Srvr.java, Compiled Code)
at weblogic.t3.srvr.T3Srvr.main(T3Srvr.java:825)
at java.lang.reflect.Method.invoke(Native Method)
at weblogic.Server.startServerDynamically(Server.java:99)
at weblogic.Server.main(Server.java:65)
at weblogic.Server.main(Server.java:55)
at weblogic.NTServiceHelper.run(NTServiceHelper.java:19)
at java.lang.Thread.run(Thread.java:479)
==============================================================
if I give it as "/taglib.tld,
this error is shown in the log file

=============================================================
Wed Feb 21 11:40:24 GMT+05:30 2001:<E> <ServletContext-sample> failure pre-compiling JSP's
weblogic.servlet.jsp.JspException: (line 1): Could not parse deployment descriptor: org.xml.sax.SAXParseException: Could not parse: taglib starting at line 1
at weblogic.servlet.jsp.JspLexer.jspException(JspLexer.java:574)
at weblogic.servlet.jsp.JspLexer.mTAGLIB_DIRECTIVE_BODY(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspLexer.mTAGLIB_DIRECTIVE(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspLexer.mDIRECTIVE(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspLexer.mSTANDARD_THING(JspLexer.java:1636)
at weblogic.servlet.jsp.JspLexer.mTOKEN(JspLexer.java:1477)
at weblogic.servlet.jsp.JspLexer.nextToken(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspLexer.parse(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspParser.doit(JspParser.java, Compiled Code)
at weblogic.servlet.jsp.JspParser.parse(JspParser.java:109)
at weblogic.servlet.jsp.Jsp2Java.outputs(Jsp2Java.java:97)
at weblogic.utils.compiler.CodeGenerator.generate(CodeGenerator.java, Compiled Code)
at weblogic.servlet.jsp.Precompiler.compileOne(Precompiler.java:116)
at weblogic.servlet.jsp.Precompiler.compile(Precompiler.java, Compiled Code)
at weblogic.servlet.internal.ServletContextImpl.precompileJSPs(ServletContextImpl.java:1166)
at weblogic.servlet.internal.dd.DescriptorLoader.createServletContext(DescriptorLoader.java, Compiled Code)
at weblogic.t3.srvr.HttpServer.loadWARContext(HttpServer.java:666)
at weblogic.t3.srvr.HttpServer.initServletContexts(HttpServer.java, Compiled Code)
at weblogic.t3.srvr.HttpServer.start(HttpServer.java:442)
at weblogic.t3.srvr.T3Srvr.start(T3Srvr.java, Compiled Code)
at weblogic.t3.srvr.T3Srvr.main(T3Srvr.java:825)
at java.lang.reflect.Method.invoke(Native Method)
at weblogic.Server.startServerDynamically(Server.java:99)
at weblogic.Server.main(Server.java:65)
at weblogic.Server.main(Server.java:55)
at weblogic.NTServiceHelper.run(NTServiceHelper.java:19)
at java.lang.Thread.run(Thread.java:479)
Wed Feb 21 11:40:24 GMT+05:30 2001:<E> <HTTP> Error creating servlet context for Web application '/weblogic/examples/jsp/tagext/sample'
weblogic.servlet.jsp.JspException: (line 1): Could not parse deployment descriptor: org.xml.sax.SAXParseException: Could not parse: taglib starting at line 1
at weblogic.servlet.jsp.JspLexer.jspException(JspLexer.java:574)
at weblogic.servlet.jsp.JspLexer.mTAGLIB_DIRECTIVE_BODY(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspLexer.mTAGLIB_DIRECTIVE(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspLexer.mDIRECTIVE(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspLexer.mSTANDARD_THING(JspLexer.java:1636)
at weblogic.servlet.jsp.JspLexer.mTOKEN(JspLexer.java:1477)
at weblogic.servlet.jsp.JspLexer.nextToken(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspLexer.parse(JspLexer.java, Compiled Code)
at weblogic.servlet.jsp.JspParser.doit(JspParser.java, Compiled Code)
at weblogic.servlet.jsp.JspParser.parse(JspParser.java:109)
at weblogic.servlet.jsp.Jsp2Java.outputs(Jsp2Java.java:97)
at weblogic.utils.compiler.CodeGenerator.generate(CodeGenerator.java, Compiled Code)
at weblogic.servlet.jsp.Precompiler.compileOne(Precompiler.java:116)
at weblogic.servlet.jsp.Precompiler.compile(Precompiler.java, Compiled Code)
at weblogic.servlet.internal.ServletContextImpl.precompileJSPs(ServletContextImpl.java:1166)
at weblogic.servlet.internal.dd.DescriptorLoader.createServletContext(DescriptorLoader.java, Compiled Code)
at weblogic.t3.srvr.HttpServer.loadWARContext(HttpServer.java:666)
at weblogic.t3.srvr.HttpServer.initServletContexts(HttpServer.java, Compiled Code)
at weblogic.t3.srvr.HttpServer.start(HttpServer.java:442)
at weblogic.t3.srvr.T3Srvr.start(T3Srvr.java, Compiled Code)
at weblogic.t3.srvr.T3Srvr.main(T3Srvr.java:825)
at java.lang.reflect.Method.invoke(Native Method)
at weblogic.Server.startServerDynamically(Server.java:99)
at weblogic.Server.main(Server.java:65)
at weblogic.Server.main(Server.java:55)
at weblogic.NTServiceHelper.run(NTServiceHelper.java:19)
at java.lang.Thread.run(Thread.java:479)
=================================================================

where am i going wrong
could U pl give me your E-mail id so that I can send you the whole program
Pl reply
Cynthia Yao
Ranch Hand

Joined: Nov 06, 2000
Posts: 92
Basically your code has no problem, it is your setting that create the problem.
Here is my basic setting for weblogic5.1
The document root should be: weblogic-root\myserver.
in myserver folder there are: classfiles (store temporary compiled jsp), clientclasses (for applets class), public_html(store html, jsp, images, WEB-INF folder), servletclasses (u bean classes, and tag files should be here).
And make sure your weblogic.property is correctly set.
More problem, email me at ruyiy@yahoo.com
Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Hi Cynthia Yao,
I think my settings are right.
I will try it again and if any probs is there I will mail you my entire code and you can send me the reply
Thanx
ajay gaur
Greenhorn

Joined: Dec 04, 2000
Posts: 16
try this one
<%@ taglib uri ="/taglib.tld" prefix ="mt" %>
or otherwise check ur .tld file.
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Mary,
Here is a step by step sample which I tested sometime back with Tomcat. Can you try this sample and let us know what happened? I don't have weblogic. Sorry. Basically both .jsp and .tld are in same dir and the tagHandler class is under the web-inf/classes dir.
http://www.javaranch.com/ubb/Forum7/HTML/002817.html
regds
maha anna
 
 
subject: Custom Tags