URL Connections

A Uniform Resource Locator (URL) specifies the location of a resource on the Web. The HTMLReaderBean class shows how to connect to a URL from within an enterprise bean.

The source code for this example is in the j2eetutorial/examples/src/ejb/htmlreader directory. To compile the code, go to the j2eetutorial/examples directory and type ant htmlreader. A sample HTMLReaderApp.ear file is in the j2eetutorial/examples/ears directory.

The getContents method of the HTMLReaderBean class returns a String that contains the contents of an HTML file. This method looks up the java.net.URL object associated with a coded name (url/MyURL), opens a connection to it, and then reads its contents from an InputStream. Before deploying the application, ...

Get J2EE™ Tutorial, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.