Hello all,

I've come across a problem with using private variables in custom tags with Tomcat. I have this tag class:

public class TestTag extends TagSupport {
    private Date testDate = new Date();

    public int doStartTag() throws JspException {
        pageContext.setAttribute("date", testDate);
        return Tag.EVAL_BODY_INCLUDE;
    }
}

accessed from a jsp via: <t:Test>${date}</Test>

There's also a tld file that defines the Test tag linked to the TestTag class with one variable (date).

If I open my browser and go to the jsp it displays the current date/time. If I then open a browser on a different machine and go to the jsp it displays the same date/time, which means (I think) that Tomcat is creating one instance of my TestTag class in the application context and handing out references to it to all users.

The problem with this is that private variables are usually used to store the value of tag attributes after they are set via setter methods. If 2 people access the tag at more or less the same time then there's a chance that one user's attributes will clobber the other's.

Can someone tell me whether I'm doing something wrong here - and if not perhaps Tomcat should be creating a separate instance of the tag class for each session?

Thanks,
Steve


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to