Learn Java for Web Development

(Tina Meador) #1

142 CHAPTER 3: Best Practices in Java EE Web Development


In the previous chapter, we saw how the action lets us encapsulate functionality
in one JSP page and include it in another; for example, you could include a header and footer as
illustrated in Listing 3-49.


Listing 3-49. Using the Action




<%-- content -%>


The action is limited to including the resource that belongs to the same web
application as the including page and specified as a relative URL.


You can use instead of to import resources in the same web application;
Listing 3-50 illustrates how to use instead of .


Listing 3-50. Using




<%-- content --%>


With the action, other than accessing resources in the same web application, you can
also access external resources or resources in a foreign context. To access an external resource,
you specify an absolute URL for the url attribute, and to access a resource in a foreign context,
you specify a value for the context attribute that represents a context path for the foreign context
along with the url attribute, which represents a context-relative path to the resource. Listing 3-51
illustrates how to use the action to import a resource from a foreign context.


Listing 3-51. Importing a Resource from a Foreign Context



Table 3-20. Attributes


Name Type Description

url String URL of the resource to import.
context String Name of the context when accessing a relative URL resource that belongs to a
foreign context.
var String Name of the exported scoped variable for the resource’s content.
scope String Scope for var.
charEncoding String Character encoding of the content at the input resource.
varReader String Name of the exported scoped variable for the resource’s content.
Free download pdf