10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ProgrammingTagsThat Accept Scripting Elements<br />

In the web service version of the hello1 application, response.jsp contains the following<br />

scriptlet, which gets the proxy that implements the service endpoint interface. It then invokes<br />

the sayHello method on the proxy, passing the user name retrieved from a request parameter:<br />

<br />

String resp = null;<br />

try {<br />

Hello hello = new HelloService().getHelloPort();<br />

resp = hello.sayHello(request.getParameter("username"));<br />

} catch (Exception ex) {<br />

resp = ex.toString();<br />

}<br />

A scripting expression is then used to insert the value of resp into the output stream:<br />

!<br />

ProgrammingTagsThat Accept Scripting Elements<br />

276<br />

Tags that accept scripting elements in attribute values or in the body cannot be programmed as<br />

simple tags; they must be implemented as classic tags. <strong>The</strong> following sections describe the TLD<br />

elements and JSP tag extension API specific to classic tag handlers. All other TLD elements are<br />

the same as for simple tags.<br />

TLD Elements<br />

You specify the character of a classic tag’s body content using the body-content element:<br />

empty | JSP | tagdependent<br />

You must declare the body content of tags that do not have a body as empty. For tags that have a<br />

body, there are two options. Body content containing custom and core tags, scripting elements,<br />

and HTML text is categorized as JSP. All other types of body content (for example, SQL<br />

statements passed to the query tag) are labeled tagdependent.<br />

Tag Handlers<br />

<strong>The</strong> classes and interfaces used to implement classic tag handlers are contained in the<br />

javax.servlet.jsp.tagext package. Classic tag handlers implement either the Tag, the<br />

IterationTag,ortheBodyTag interface. Interfaces can be used to take an existing <strong>Java</strong> object<br />

and make it a tag handler. For newly created classic tag handlers, you can use the TagSupport<br />

and BodyTagSupport classes as base classes. <strong>The</strong>se classes and interfaces are contained in the<br />

javax.servlet.jsp.tagext package.<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!