[ Team LiB ] Previous Section Next Section

Workshop

The Workshop is designed to help you review what you have learned, and help you to further increase your understanding of the material covered in this hour.

Quiz

1:

What file extension is used to identify JavaServer Pages?

2:

What is the name of the method that performs most of the work servicing a JSP?

3:

Why won't the following code work?


<%! public void printName() {
    out.print("My Name")
} %>


Answers

A1:

Top-level JSP files are identified by the use of the .jsp extension. JSPs may also be divided into segments that are statically included into top-level files. The JSP 2.0 standard suggests that you use a .jspf extension for these in order to maintain consistency with earlier specifications that referred to files with partial JSPs in them as fragments. In addition, JSPs can be delivered as XML documents, in which case the extension .jspx is used.

A2:

The method jspService() is used to do most of the work. This method contains the scriptlets and expressions found in your JSP. Declarations from your JSP occur outside of this method.

A3:

The out variable is available only within the scope of jspService(). Since this is a method declaration, the method printName() occurs outside of the scope of jspService, and it does not have access to out.


Activity

Write a simple JavaServer Page using a scriptlet, an expression, and a declaration. Access the page from a Web browser to make sure it works and to produce the source code for the servlet that handles your request. Take a moment to examine the generated source code.

    [ Team LiB ] Previous Section Next Section