Forums Register Login

Problem with <jsp:attribute> standard action

+Pie Number of slices to send: Send
Hi, I am trying to use the <jsp:attribute> action in my program.

In my program I want to pass an attribute value from a JSP to a tag file.

My JSP is as follows:

The Fruit.jsp file

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="t" tagdir="/WEB-INF/tags" %>

<c:set var="f" value="apple" />

<t:MyTag>
    <jsp:attribute name="fruit">
      ${f}
    </jsp:attribute>
</t:MyTag>

The MyTag.tag file

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@attribute name="fruit" %>


<c:out value="${fruit}" />
<jsp:doBody />


I am using Apache Tomcat 6.0.26 Server. When I type the url in the browser, I get the following error:

Fruit.jsp(7,9) jsp:attribute must be the subelement of a standard or custom action.

To the best of my knowledge, the MyTag tag is my custom action.

Can somebody assist me to identify what the problem is?

Regards,
John
+Pie Number of slices to send: Send
The c:out in MyTag.tag is missing some quotes and a closing tag.
+Pie Number of slices to send: Send
Hi Jelle, Thanks for pointing this out. Actually this particular error was a typing error. I have edited my question. I am still getting the error that I had originally mentioned.

Regrads,
John
+Pie Number of slices to send: Send
Hmm, this should work, provided you're deploying correctly on a JSP 2.0 compliant servlet container, which Apache Tomcat 6.0.26 is.
Could you provide a little more info on the file structure of the web application and maybe the relevant bits of the web.xml?
+Pie Number of slices to send: Send
Hello Jelle,

My file structure is mentioned below:

The Fruit.jsp file

E:\tomcat\webapps\ROOT\fruitpack\Fruit.jsp


The MyTag.tag file

E:\tomcat\webapps\ROOT\WEB-INF\tags


The URL that I type in my browser is:

http://localhost:8080/fruitpack/Fruit.jsp

The web.xml file

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
<display-name>
Welcome to Tomcat</display-name>

</web-app>

My web.xml file contains mappings for filters, listeners and servlets. I have not indicated the mappings in this post as I have not used web.xml file for this particular page. I mean, I have placed my tag files in the 'tags' directory and have mentioned the directory path on the JSP as the value of the taglib's 'tagdir' attribute.


I also want to point out that my other tags where <jsp:attribute> is not used are working fine.

Regards,
John.
+Pie Number of slices to send: Send
Regardless of the peculiar location i.e. within the ROOT application, I'm not seeing any problems here.
+Pie Number of slices to send: Send
Yeah, I tried by removing all filter and listener mappings in web.xml file. I also tried using different browsers (Chrome & Internet Explorer). But <jsp:attribute> action does not work on my JSP.

+Pie Number of slices to send: Send
@Johnnie Smith - did you manage to resolve this issue?
It looks very much like something I'm experiencing now.
+Pie Number of slices to send: Send
Got my issue fixed, ended up with something like:

JSP:


Tagfile:


Hope that helps someone.
+Pie Number of slices to send: Send
Just to add to this post.

One of the errors that i faced was due to a comment that was written between the container tag and the jsp:attribute tag. It basically means that there should be no content (not even a comment) between <template:page> and the <jsp:attribute> tags

For example: Using the same example given above. If i add a comment.
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="template" tagdir="/WEB-INF/tags/mypagetemplates" %>

<template:page>
<!- some useless comment which will throw this subelement error ->
<jsp:attribute name="headContent">
some html stuff
</jsp:attribute>
<jsp:body>
main html content
</jsp:body>
</template:page>
machines help you to do more, but experience less. Experience this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 10946 times.
Similar Threads
problem with jstl tags
Custom tag with .tag files
Error when using xml tags
Cannot find a setter
how to use CORE custom tab in jsp JSTL
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 20:29:46.