10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Examples: SecuringWeb Applications<br />

878<br />

Building, Packaging, and Deploying the Servlet Basic Authentication<br />

Example Using Ant<br />

To build, package, and deploy the web/hello2_basicauth example using the Ant tool, follow<br />

these steps:<br />

1. If you have not already done so, follow the instructions in “Building the Examples” on<br />

page 69. This step is necessary to provide the Ant targets with the location of your tutorial<br />

and Application Server installations.<br />

2. If you have not already done so, add authorized users to the file realm of the Application<br />

Server as described in “Adding Authorized Roles and Users” on page 876.<br />

3. From a terminal window or command prompt, change to the<br />

tut-install/javaeetutorial5/examples/web/hello2_basicauth/ directory.<br />

4. Build and package the web application by entering the following command at the terminal<br />

window or command prompt:<br />

ant<br />

This command uses web.xml and sun-web.xml files, located in the<br />

tut-install/javaeetutorial5/examples/web/hello2_basicauth/web/WEB-INF/ directory.<br />

5. To deploy the example using Ant, enter the following command at the terminal window or<br />

command prompt:<br />

ant deploy<br />

<strong>The</strong> deploy target in this case gives you an incorrect URL to run the application. To run the<br />

application, please use the URL shown in “Running the Basic Authentication Servlet” on<br />

page 878.<br />

6. To run the web application, follow the steps in “Running the Basic Authentication Servlet”<br />

on page 878.<br />

Running the Basic Authentication Servlet<br />

To run the web client, follow these steps:<br />

1. Open a web browser.<br />

2. Enter the following URL in your web browser:<br />

http://localhost:8080/hello2_basicauth/greeting<br />

If you set the transport guarantee to CONFIDENTIAL as discussed in “Protecting<br />

Passwords with SSL” on page 875, you must load the application in a web browser using<br />

https for the protocol, the HTTPS port that you specified during installation for the port<br />

(by default this port is 8181), and the context name for the application you wish to run. For<br />

the basic authentication example, you could run the example using the following URL:<br />

https://localhost:8181/hello2_basicauth/greeting.<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!