Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A tld file related question

Status
Not open for further replies.

cyan01

Programmer
Mar 13, 2002
143
0
0
US
Hi, Experts,

I am new to jsp. And right now I am having a hard time to get an example working.

The following is my tag file, named as calalog.tag. The file path is: %CATALINA_HOME%\webapps\myjsp\WEB-INF\tags

Code:
<%@ attribute name="normalPrice" fragment="true" %>
  <%@ variable fragment="normalPrice" name-given="name" %>
  <%@ variable fragment="normalPrice" name-given="price" %>

<%@ attribute name="onSale" fragment="true" %>
  <%@ variable fragment="onSale" name-given="name" %>
  <%@ variable fragment="onSale" name-given="origPrice" %>
  <%@ variable fragment="onSale" name-given="salePrice" %>

<table border="1">
  <tr>
    <td> 
      <jsp:invoke fragment="normalPrice">
        <jsp:param name="name" value="Hand-held Color PDA"/>
        <jsp:param name="price" value="$298.86"/>
      </jsp:invoke>
    </td>
    <td> 
      <jsp:invoke fragment="onSale">
        <jsp:param name="name" value="4-Pack 150 Watt Light Bulbs"/>
        <jsp:param name="origPrice" value="$2.98"/>
        <jsp:param name="salePrice" value="$2.32"/>
      </jsp:invoke>
    </td>
    <td> 
      <jsp:invoke fragment="normalPrice">
        <jsp:param name="name" value="Digital Cellular Phone"/>
        <jsp:param name="price" value="$68.74"/>
      </jsp:invoke>
    </td>
    <td> 
      <jsp:invoke fragment="normalPrice">
        <jsp:param name="name" value="Baby Grand Piano"/>
        <jsp:param name="price" value="$10,800.00"/>
      </jsp:invoke>
    </td>
    <td> 
      <jsp:invoke fragment="onSale">
        <jsp:param name="name" value="Luxury Car w/ Leather Seats"/>
        <jsp:param name="origPrice" value="$23,980.00"/>
        <jsp:param name="salePrice" value="$21,070.00"/>
     </jsp:invoke>
    </td>
  </tr>
</table>

The following is my jsp file, named as shopping.jsp. The path is %CATALINA_HOME%\webapps\myjsp\ch09\Libraries.

Code:
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<html>
  <head>
    <title>Shopping: A Simple Tag Example</title>
  </head>
  <body>
    <h1>ABC Store: New Year Sale</h1>
    <hr>
    <h2>$$ Weekend Prices...Hurry$$</h2>
   <tags:catalog>
      <jsp:attribute name="normalPrice">
        ${name}<br/>
        ${price}
      </jsp:attribute>
      <jsp:attribute name="onSale">
        Item: ${name}<br/>
        <font color="red">
        <strike>Was: ${origPrice}</strike></font><br/>
        <b>Now: ${salePrice}</b>
      </jsp:attribute>
   </tags:catalog>

  </body>
</html>

According to the book, it don't need a TLD file, as the container will generate an implicit TLD for it. However, when I tried to run the JSP in my IE 6.0. I got following error:

HTTP Status 500 -

------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:565)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:296)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.lang.RuntimeException: org.apache.jasper.JasperException: /WEB-INF/tags/catalog.tag(2,3) Variable directive has invalid attribute: fragment
org.apache.jasper.compiler.ImplicitTagLibraryInfo.getTagFile(ImplicitTagLibraryInfo.java:129)
org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1306)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1560)
org.apache.jasper.compiler.Parser.parse(Parser.java:126)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:211)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:100)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:146)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:296)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


It seems to me that tomcat doce not know the tag - fragment.

Could someone please explain it to me? Many thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top