Discussions

Web tier: servlets, JSP, Web frameworks: How to catch values from a JSP Tag library

  1. How to catch values from a JSP Tag library (2 messages)

    Hi All,
    I have a problem. I have a custom tag which takes two attributes and validates inside the class. OK. I want to return a value to the JSP from the Tag class. where should i write code for that. How to return a value to a JSP page
  2. Srinivasa, to return a value from your tag handler to the JSP page, you'd write code the doStartTag() method of your tag handler that looks something like this:

    public int doStartTag() throws JspException
    {
    ...
    JspWriter out = pageContext.getOut();
    try
    {
       out.println("<h1>");
       out.println("Hello World!")
       out.println("</h1>");
    }
    catch(IOException e)
    {
       throw new JspTagException("Unable to write tag output");
    }
    ...
    return SKIP_BODY;
    }

    Regards,

    Gordon.
  3. Srini,

    The sample code by Gordon will write the output of the tag to the JSP page.

    If you want to pass value from the tag to JSP(for example storing some value in a variable in the tag and accessing in the JSP) you have to use TagExtraInfo class and define your variable and then can use it in the JSP.

    For further details refer http://www.weblogic.com/docs51/classdocs/API_taglib.html

    Srinivas.J