[ Team LiB ] Previous Section Next Section


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.



What file extension is used to identify JavaServer Pages?


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


Why won't the following code work?

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



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.


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.


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.


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