How can a Classic tag handler instruct the container to ignore the remainder of the JSP that invoked the tag?
(Choose all that apply.)
Which directives and/or standard actions are applicable ONLY within tag files? (Choose all that apply.)
A medical website hides selective content from users who are not registered. In place of the hidden content, a message should display to encourage users to register. Given the Simple tag handler snippet:
11. public void doTag() throws JspException, IOException { 12. String level = 13. (String) getJspContext().findAttribute("accountLevel"); 14. if((level == null || "trial".equals(level))) { 15. String price = "?"; // TODO get context param 16. String message = "Content for paying members only.<br/>"+ 17. "<a href="register.jsp">Sign up now for only "+price+"!</a>"; 18. getJspContext().getOut().write(message); 19. } else { 20. getJspBody().invoke(null); 21. } 22. }
At line 15, the price for registration should be retrieved from a context parameter named registrationFee, however there are no methods on JspContext for retrieving context parameters. What can solve this problem?
A. | Retrieve the value with | |
B. | Cast the | |
C. | Retrieve the value with | |
D. | Throw an exception to let the user know that the price could not be found. | |
E. | This is impossible with a Simple tag. A Classic tag must be used. |
Which Simple tag mechanism will tell a JSP page to stop processing?
Which are true about the Classic tag model? (Choose all that apply.)
A. | The | |
B. | The | |
C. | The | |
D. | The | |
E. | There are three tag interfaces— |
Which must be true if you want to use dynamic attributes for a Simple tag handler? (Choose all that apply.)
A. | Your Simple tag must NOT declare any static tag attributes. | |
B. | Your Simple tag must use the | |
C. | Your Simple tag handler must implement the | |
D. | Your Simple tag should extend the | |
E. | Your Simple tag CANNOT be used with the |
Which is true about tag files? (Choose all that apply.)
Given:
10. public class BufTag extends BodyTagSupport { 11. public int doStartTag() throws JspException { 12. // insert code here 13. } 14. }
Assume that the tag has been properly configured to allow body content.
Which, if inserted at line 12, would cause the JSP code <mytags:mytag>BodyContent</mytags:mytag>
to output BodyContent
?
Which about doAfterBody()
is true? (Choose all that apply.)
A. |
| |
B. |
| |
C. | Assuming no exceptions occur, | |
D. | Assuming no exceptions occur, | |
E. | Assuming no exceptions occur, |
Given a JSP page:
1. <%@ taglib prefix="my" uri="/WEB-INF/myTags.tld" %> 2. <my:tag1> 3. <%-- JSP content --%> 4. </my:tag1>
The tag handler for my:tag1
is Tag1Handler
and extends TagSupport. What happens when the instance of Tag1Handler
calls the getParent
method? (Choose all that apply.)
Which is true about the lifecycle of a Simple tag? (Choose all that apply.)
A. | The | |
B. | The | |
C. | The | |
D. | The |
Given:
10. public class ExampleTag extends TagSupport { 11. private String param; 12. public void setParam(String p) { param = p; } 13. public int doStartTag() throws JspException { 14. // insert code here 15. // more code here 16. } 17. }
Which, inserted at line 14, would be guaranteed to assign the value of the request-scoped attribute param
to the local variable p
? (Choose all that apply.)
Which are valid method calls on a PageContext
object? (Choose all that apply.)
Which is the most efficient JspContext
method to call to access an attribute that is known to be in application scope?
What is the best strategy, when implementing a custom tag, for finding the value of an attribute whose scope is unknown?
A. | Check all scopes with a single | |
B. | Check all scopes with a single | |
C. | Check each scope with calls to | |
D. | Call | |
E. | None of these will work. |
Given a tag, simpleTag
, whose handler is implemented using the Simple tag model and a tag, complexTag
, whose handler is implemented using the Classic tag model. Both tags are declared to be non-empty and non-tag dependent in the TLD.
Which JSP code snippets are valid uses of these tag? (Choose all that apply.)
Which are true about the Tag File model? (Choose all that apply.)
A. | Each tag file must have a corresponding entry in a TLD file. | |
B. | All directives allowed in JSP pages are allowed in Tag Files. | |
C. | All directives allowed in Tag Files are allowed in JSP pages. | |
D. | The | |
E. | The allowable file extensions for Tag Files are | |
F. | For each attribute declared and specified in a Tag File, the container creates a page-scoped attribute with the same name. |
Which are valid in tag files? (Choose all that apply.)
Which returns the enclosing tag when called from within a tag handler class? (Choose all that apply.)
Given a web application structure:
/WEB-INF/tags/mytags/tag1.tag /WEB-INF/tags/tag2.tag /WEB-INF/tag3.tag /tag4.tag
Which tags could be used by an appropriate taglib
directive? (Choose all that apply.)
A web application includes many forms for users to fill out and submit. Nothing in the pages indicates that a field is required. Business decided that a red asterisk should be placed preceding the text labels of required fields but the project manager is contending that the background color of required fields be light blue and another department is demanding that the project’s application be consistent with their own, where the text of the labels be bold for required fields.
Considering the different perspectives on how required fields could be identified in pages, choose the most maintainable usage of a custom tag.