By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,569 Members | 1,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,569 IT Pros & Developers. It's quick & easy.

Including javascript in a JSP tld

P: n/a

Hi,

How do you include javascript in the definition of a jsp TLD. for
example if i have a TLD called <mytld: body everytime I include this
in a page, I also want some javascript to be included.

Is this done in the Java definition of the tld element ?

How?

Sep 1 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

misdst23 wrote:
Hi,

How do you include javascript in the definition of a jsp TLD.
You don't. TLDs don't generate output. They only expose classes and
methods.

for
example if i have a TLD called <mytld: body everytime I include this
in a page, I also want some javascript to be included.
Modify the tag referred to by <mytld:bodyto include the javascript in
it's output to the response stream. You can either write a script tag
that points to a separate .js file:

pageContext.getOut().println("<script type=\"text/javascript\"
src=\"/path/to/javascript.js\">");

or write out the javascript (which would be horribly tedious):

JspWriter out = pageContext.getOut();
out.println("<script type=\"text/javascript\">");
out.println("alert('Oh my goodness!');");
out.println("</script>");

HTH.

>
Is this done in the Java definition of the tld element ?
No, but if you wanted to you could include a attribute (let's call it
script) that would set where the script file is located and you could
use it as the src in my first example...(just an idea).

BTW, did you write these tags? You don't seem to have a complete
understanding of how they work...
>
How?
Sep 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.