Using a dot tag file with JSP

A

Alfonso

I downloaded an example called products.jsp and dipslayProducts.tag
that I want to modify, but I can get the above two files to work. I am
using Tomcat 5. Below is the text of the two files, followed by the
error.

/webapp/products/products.jsp
%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<html>
<head>
<title>JSP 2.0 Examples - Display Products Tag File</title>
</head>
<body>
<h1>JSP 2.0 Examples - Display Products Tag File</h1>
<hr>
<p>This JSP page invokes a tag file that displays a listing of
products. The custom tag accepts two fragments that enable
customization of appearance. One for when the product is on sale
and one for normal price.</p>
<p>The tag is invoked twice, using different styles</p>
<hr>
<h2>Products</h2>
<tags:displayProducts>
<jsp:attribute name="normalPrice">
Item: ${name}<br/>
Price: ${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:displayProducts>
<hr>
<h2>Products (Same tag, alternate style)</h2>
<tags:displayProducts>
<jsp:attribute name="normalPrice">
<b>${name}</b> @ ${price} ea.
</jsp:attribute>
<jsp:attribute name="onSale">
<b>${name}</b> @ ${salePrice} ea. (was: ${origPrice})
</jsp:attribute>
</tags:displayProducts>
</body>
</html>

webapps\ROOT\WEB-INF\tags\displayProducts.tag
<%--
- Copyright (c) 2002 The Apache Software Foundation. All rights
- reserved.
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ attribute name="normalPrice" fragment="true" %>
<%@ attribute name="onSale" fragment="true" %>
<%@ variable name-given="name" %>
<%@ variable name-given="price" %>
<%@ variable name-given="origPrice" %>
<%@ variable name-given="salePrice" %>

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

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: /products.jsp(17,11) jsp:attribute
must be the subelement of a standard or custom action
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:376)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:90)
org.apache.jasper.compiler.Parser.parseStandardAction(Parser.java:1237)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1559)
org.apache.jasper.compiler.Parser.parse(Parser.java:126)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:220)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:101)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:203)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:461)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:442)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:430)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:274)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

note The full stack trace of the root cause is available in the Apache
Tomcat/5.0.25 logs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top