• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Problem with custom tags

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
We're being followed by intergalactic spies! Quick! Take this tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic