• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with <jsp:attribute> standard action

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The c:out in MyTag.tag is missing some quotes and a closing tag.
 
Johnnie Smith
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Johnnie Smith
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Regardless of the peculiar location i.e. within the ROOT application, I'm not seeing any problems here.
 
Johnnie Smith
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Johnnie Smith - did you manage to resolve this issue?
It looks very much like something I'm experiencing now.
 
Benny Gee
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got my issue fixed, ended up with something like:

JSP:


Tagfile:


Hope that helps someone.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Rototillers convert rich soil into dirt. Please note that this tiny ad is not a rototiller:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic