File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes TagExtraInfo Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "TagExtraInfo Question" Watch "TagExtraInfo Question" New topic

TagExtraInfo Question

Chris Salivar
Ranch Hand

Joined: May 25, 2001
Posts: 34
Can anybody tell me why I am getting the 'Undefined variable: name' error in my JSP for the following code running on orion server:
<%@ taglib uri="mytags" prefix="mt" %>
Inside the body of the tag <%=name%>
import javax.servlet.jsp.tagext.*;
public class HelloTagExtraInfo extends TagExtraInfo {
public HelloTagExtraInfo() {
public VariableInfo[] getVariableInfo(TagData data) {
return new VariableInfo[] {
new VariableInfo(
"name", "java.lang.String",
true, VariableInfo.AT_BEGIN)};
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.util.*;
public class HelloTag extends TagSupport
public HelloTag() {
public int doStartTag() throws JspTagException {
pageContext.setAttribute("name", "chris");
public int doEndTag() throws JspTagException {
return EVAL_PAGE;
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "">
<tlibversion>1.0</tlibversion> <jspversion>1.1</jspversion>
<info>A simple hello</info>
It works fine if I remove the name expression outside the tag body in the JSP page.
- Chris
Cameron Park
Ranch Hand

Joined: Apr 06, 2001
Posts: 371
The scope for a variable defined in a TagExtraInfo is NESTED by default. In other words, it is not accessible after the particular closing tag unless you explicitly define it otherwise.
ken chou
Ranch Hand

Joined: Feb 08, 2001
Posts: 68

On your jsp page, you need to declare the varable "name" like the following:
<%! String name = null; %>
Chris Salivar
Ranch Hand

Joined: May 25, 2001
Posts: 34
Cameron, I have declared the scope of the variable to be AT_BEGIN so its not the default one.
Ken, declaring a variable in the JSP page would beat the purpose of using custom tags because we don't want to use java code in the JSP page.
Is it some other problem? Anybody?
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
It should work with a scope of AT_BEGIN. Which server are you using?
Simon Brown
Co-author of Professional JSP 2nd Edition
Chris Salivar
Ranch Hand

Joined: May 25, 2001
Posts: 34
Thanks Simon, it magically started working when i woke up in the morning and tried it again. BTW I am using the orion server.
- Chris
I agree. Here's the link:
subject: TagExtraInfo Question
It's not a secret anymore!