Get your CodeRanch badge!*
The moose likes Servlets and the fly likes Problem with custom tags Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with custom tags" Watch "Problem with custom tags" New topic
Author

Problem with 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

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Mary, I remember seeing you post about JSP custom tag problem a couple of months ago. At that time, I ran into the same trouble (cannot parse tag library descriptor file). Now, I am back working on the custom tag again. I am stuck with the same problem. I am using the WebLogic 6.0 and 5.1.0. Nobody has responded to this particular problem. I don't know what to do either.
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
Mary, you have a couple of typos in your <!DOCTYPE> element:
1. There is an errant space between <! and DOCTYPE
2. The system identifier has "web-jsptaglibrary" spelled wrong.
Fix those and see if that works.
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
Website: http://www.philhanna.com


Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Mr. Hanna, I am exited about your response. I am using the WebLogic 6.0. I put a space between ! and DOCTYPE and re-run my very simple JSP Custom Tag, I still got the same error message:
Parsing of JSP File '/SimpleExample.jsp' failed:
---------------------------------------------------------------
/SimpleExample.jsp(6): Could not parse deployment descriptor: java.io.IOException: cannot resolve 'csajsp-taglib.tld' into a valid tag library
probably occurred due to an error in /SimpleExample.jsp line 6:
<%@ taglib uri="csajsp-taglib.tld" prefix="csajsp" %>
---------------------------------------------------------------
Thu Apr 13 17:46:05 EDT 2000
There are five, but very small files involved. Please allow me to load my source code:
1. The Web application deployment descriptor, web.xml, under
c:\bea\wlserver6.0sp1
\config\mydomain\applications\DefaultWebApp_myserver
\WEB-INF
<?xml version="1.0" ?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<taglib>
<taglib-uri>csajsp-taglib.tld</taglib-uri>
<taglib-location>csajsp-taglib.tld</taglib-location>
</taglib>
</web-app>

2. The tag library descriptor file, csajsp-taglib.tld, which is a .xml file, is under the same directory as where web.xml is
c:\bea\wlserver6.0sp1
\config\mydomain\applications\DefaultWebApp_myserver
\WEB-INF
<?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">
<!-- a tag library descriptor -->
<taglib>
<!-- after this the default space is
"http://java.sun.com/j2ee/dtds/jsptaglibrary_1_2.dtd"
-->
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>csajsp</shortname>
<urn></urn>
<info>
A tag library from Core Servlets and JavaServer Pages,
http://www.coreservlets.com/.
</info>
<tag>
<name>example</name>
<tagclass>coreservlets.tags.ExampleTag</tagclass>
<info>Simplest example: inserts one line of output</info>
<!-- TOMCAT 3.1 DOES NOT SUPPORT BODYCONTENT
<bodycontent>empty</bodycontent> -->
</tag>
</taglib>

3. The JSP page, SimpleExample.jsp is under
c:\bea\wlserver6.0sp1
\config\mydomain\applications\DefaultWebApp_myserver
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<%@ taglib uri="csajsp-taglib.tld" prefix="csajsp" %>
<TITLE><csajsp:example /></TITLE>
<LINK REL=STYLESHEET
HREF="JSP-Styles.css"
TYPE="text/css">
</HEAD>
<BODY>
<H1><csajsp:example /></H1>
<csajsp:example />
</BODY>
</HTML>
4. The style sheet that is used in the JSP page, JSP-Styles.css, is in the same directory as where the JSP page is
<STYLE TYPE="text/css">
<!--
BODY { background-color: #FDF5E6 }
A:hover { color: red }
H1 { color: #440000;
text-align: center;
font-family: Arial Black, Arial, Helvetica, sans-serif
}
H2 { color: #440000;
text-align: left;
font-family: Arial, Helvetica, sans-serif
}
H3 { color: #440000;
text-align: left;
font-family: Arial, Helvetica, sans-serif
}
UL { margin-top: 0;
border-top-width: 0;
padding-top: 0
}
DT { font-weight: bold;
}
PRE { font-size: 105%;
}
CODE { font-size: 105%;
}
.TOC { font-size: 90%;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif
}
TH.COLORED { background-color: #FFAD00
}
TR.COLORED { background-color: #FFAD00
}
TH.TITLE { background-color: #EF8429;
font-size: 28px;
font-family: Arial, Helvetica, sans-serif;
}
-->
</STYLE>
5. The tag handler Java class file, ExampleTag.class, is under
c:\bea\wlserver6.0sp1
\config\mydomain\applications\DefaultWebApp_myserver
\WEB-INF\classes\coreservlets\tags
and the below is the source code for the tag handler Java file, Example.java

package coreservlets.tags;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
public class ExampleTag extends TagSupport {
public int doStartTag() {
try {
JspWriter out = pageContext.getOut();
out.print("Custom tag example " +
"(coreservlets.tags.ExampleTag)");
} catch(IOException ioe) {
System.out.println("Error in ExampleTag: " + ioe);
}
return(SKIP_BODY);
}
}
Could you detect what went wrong? Many, many thanks
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Mr. Hanna, I alse used the WebLogic 5.1.0 to test the same JSP Custom Tag. I got the same error message: cannot parse the descriptor file. I wonder if compiled the ExampleTag.java correctly. The ExampleTag.java is in package coreservlets.tags.
Thanks again.
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
JiaPei, the way to figure this out is to work your way through the error message according to the DTD and the JSP specification:
Parsing of JSP File '/SimpleExample.jsp' failed:
---------------------------------------------------------------
/SimpleExample.jsp(6): Could not parse deployment descriptor: java.io.IOException: cannot resolve 'csajsp-taglib.tld' into a valid tag library
probably occurred due to an error in /SimpleExample.jsp line 6:
<%@ taglib uri="csajsp-taglib.tld" prefix="csajsp" %>
---------------------------------------------------------------
This tells you that "csajsp-taglib.tld" could not be found. Well, where are you specifying it? Your web.xml has this:
<taglib>
<taglib-uri>csajsp-taglib.tld</taglib-uri>
<taglib-location>csajsp-taglib.tld</taglib-location>
</taglib>
What should these entries be? At the top of your web.xml, you have the URL for the DTD: http://java.sun.com/j2ee/dtds/web-app_2_2.dtd
This DTD says <taglib-location> should contain "the location (as a resource relative to the root of the web application) where to find the Tag Library Descriptor file for the tag library."
So, since the root of your web application is c:\bea\wlserver6.0sp1
\config\mydomain\applications\DefaultWebApp_myserver, you are saying that the file is c:\bea\wlserver6.0sp1
\config\mydomain\applications\DefaultWebApp_myserver\csajsp-taglib.tld.
But that's not where you put the file - you said it's one level lower, in the WEB-INF directory (which is a better place for it, by the way). So your taglib-location element ought to be
<taglib-location>/WEB-INF/csajsp-taglib.tld</taglib-location>
That may not be the only error, but if you correct that and restart your server, it will either work or you'll get a better error message.
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
Website: http://www.philhanna.com
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Mr. Hanna, Thank you for taking a look at my code. My tag library descriptor file, csajsp-taglib.tld was and is under
c:\bea\wlserver6.0sp1
\config\mydomain\applications\DefaultWebApp_myserver\WEB-INF
Pursuant to your comment, my web.xml file looks like:
<?xml version="1.0" ?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<taglib>
<taglib-uri>csajsp-taglib.tld</taglib-uri>
<taglib-location>/WEB-INF/csajsp-taglib.tld</taglib-location>
</taglib>
</web-app>
I typed http://localhost:7001/SimpleExample.jsp in the IE browser, and the error message is the same:
Parsing of JSP File '/SimpleExample.jsp' failed:

/SimpleExample.jsp(6): Could not parse deployment descriptor: java.io.IOException: cannot resolve 'csajsp-taglib.tld' into a valid tag library
probably occurred due to an error in /SimpleExample.jsp line 6:
<%@ taglib uri="csajsp-taglib.tld" prefix="csajsp" %>

Thu Apr 13 19:24:46 EDT 2000
I really don't know what to do. Please help.

Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Hi all,
Well am unable to run the sample file only which is provided by Weblogic5.1.The other sample files are running perfectly.
I have posted my probs in http://www.javaranch.com/ubb/Forum40/HTML/000256.html
Phil, I corrected the typos which I made above , but no result
I have loaded service pack8 for weblogic 5.1 and still same error persists
Pl reply what setting I have to make for this prob

Phil, I have another request for you.I have a .war file(struts.war provided by Apache) and How should I register it in weblogic5.1.What changes should I make in the properties file.
Waiting for ur reply
Mary
[This message has been edited by Mary, Cole (edited April 26, 2001).]
 
Consider Paul's rocket mass heater.
 
subject: Problem with custom tags
 
Similar Threads
Unable to open tld : Error
Custom Tags
Class not found..
error in opening tld
Cannot resolve symbol