| Author |
Problem with <jsp:attribute> standard action
|
Johnnie Smith
Greenhorn
Joined: May 02, 2012
Posts: 15
|
|
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
|
 |
Jelle Klap
Bartender
Joined: Mar 10, 2008
Posts: 1430
|
|
|
The c:out in MyTag.tag is missing some quotes and a closing tag.
|
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
|
 |
Johnnie Smith
Greenhorn
Joined: May 02, 2012
Posts: 15
|
|
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
Joined: Mar 10, 2008
Posts: 1430
|
|
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
Joined: May 02, 2012
Posts: 15
|
|
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
Joined: Mar 10, 2008
Posts: 1430
|
|
|
Regardless of the peculiar location i.e. within the ROOT application, I'm not seeing any problems here.
|
 |
Johnnie Smith
Greenhorn
Joined: May 02, 2012
Posts: 15
|
|
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.
|
 |
Benny Gee
Greenhorn
Joined: Nov 28, 2011
Posts: 3
|
|
@Johnnie Smith - did you manage to resolve this issue?
It looks very much like something I'm experiencing now.
|
 |
Benny Gee
Greenhorn
Joined: Nov 28, 2011
Posts: 3
|
|
Got my issue fixed, ended up with something like:
JSP:
Tagfile:
Hope that helps someone.
|
 |
Mehta Tejas
Greenhorn
Joined: Aug 16, 2009
Posts: 15
|
|
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>
|
 |
 |
|
|
subject: Problem with <jsp:attribute> standard action
|
|
|