Learn Java for Web Development

(Tina Meador) #1
CHAPTER 3: Best Practices in Java EE Web Development 145

If you specify a context-relative or page-relative URL for the value attribute, prepends
the context path of the web application to the URL; for example, if the context path of the web
application is /bookWeb/books, the action will result
inurl:/bookWeb/books/book.jsp.


The Action


The action sends an HTTP redirect to the client, redirecting the browser to an alternate
URL. The action provides the URL rewriting with a redirect.


Here’s the syntax without body content:


<c:redirect url="value" [context="context"]/>


Here’s the syntax with body content to specify query string parameters:


<c:redirect url="value" [context="context"]>


subtags

The action has two attributes: the URL that will be used to redirect to and an optional context.


The attributes of are listed in the Table 3-23.


Table 3-23. Attributes


Name Type Description

url String The URL of the resource to redirect to
context String The name of the context when redirecting to a relative URL resource that belongs to
a foreign context

The URL, relative or absolute, follows the same URL rewriting rules as . Listing 3-55
illustrates redirecting to an external resource, which is an absolute URL.


Listing 3-55. Using



You can redirect to a resource in a foreign context using the context attribute. The URL specified
must start with a / as a context-relative URL, and as defined, the context name must also start with
a /. Listing 3-56 illustrates redirecting to a foreign resource in a foreign context.


Listing 3-56. redirecting to a foreign resource in a foreign context.



In this chapter, we have looked at the nuts and bolts of the Java EE machine in the web tier: the web
components (servlets and JSP), the feature-rich Expression Language, and the ready-to-use custom
actions (JSTL). Now we’ll talk about best-practice solutions using patterns.

Free download pdf