Including javascript in a JSP tld

M

misdst23

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?
 
T

Tom Cole

misdst23 said:
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:body> to 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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,016
Latest member
TatianaCha

Latest Threads

Top