private PageContext pagecontext; private Tag parent;
public int doStartTag() throws JspException { return SKIP_BODY; }
public int doEndTag () throws JspException { try { pagecontext.getOut().write("Hello World"); } catch(java.io.IOException ex) { throw new JspException("IO Exception"); } return EVAL_PAGE; }
public void release (){}
public void setPageContext(PageContext p) { pagecontext=p; }
public void setParent(Tag t) { parent = t; }
public Tag getParent() { return parent; } }
Since this is the first taglib tutorial I've ever tried, it was frustrating. It took me many hours to find out why.
The problem is in your class.
First of all, "Package" is lowercase. "Import" is also all lowercase. "Public" is also all lowercase.
"PageContext" needs to have capital "P" and "C", not just capital "P". The property "pagecontext" doesn't have a capital "C".
The "JSPException" is also misspelled. It should be "JspException."
In the try/catch, "java.io.Exception" should be "java.io.IOException" - there is no "Exception"...it doesn't exist.
In your setPageContext() method, the data type of variable p is PageContext, not pageContext.
In your getParent() method, you have "void" for return type. It should be "Tag" instead of void.
You used illegal double quotes in 2 argument lists.
pagecontext.getOut().write()
and
throw new JspException()
They seem to be extended ASCII double quotes, probably from Microsoft Word, or UTF-8 encoding. They won't work strings in argument lists!
Also, in your setParent() method, the assignment is incorrect. You are assigning it to a variable which isn't declared. It should be this: pagecontext=p;
Not this: pageContext=p;
Even though your code is horrible, I learned a lot by fixing it. Sir, you can't just put tutorials like this online without testing the code for yourself! There are a lot of beginners who need good tutorials. They need help, not confusion.
View All Comments
| View Tutorial