Listing 5: TestMyCookieHandler.java
import java.io.*;
import java.net.*;
import java.util.*;
public class TestMyCookieHandler{
public static void main(String args[]) throws Exception {
URL url=null; //the requested URL
URLConnection URLconn=null;
//try to find a default cookie manager
if(CookieHandler.getDefault()!=null)
{
System.out.println("Surprize - it does ...");
}else
{
//setting your cookie manager
CookieHandler.setDefault(new MyCookieHandler());
//optional - for proxy connection used
InetAddress addr=InetAddress.getByName("www-proxy.petrom.com");
InetSocketAddress ISA=new InetSocketAddress(addr,8080);
java.net.Proxy proxy=new java.net.Proxy(java.net.Proxy.Type.HTTP,ISA);
//first time - http://www.DexX.com
System.out.println("\nFirst time\n");
url=new URL("http://www.DevX.com");
URLconn=url.openConnection(proxy);
Object content=URLconn.getContent();
//second time - http://www.DevX.com
System.out.println("\nSecond time\n");
url=new URL("http://www.DevX.com");
URLconn=url.openConnection(proxy);
content=URLconn.getContent();
}
}
}
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|