public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException{
String userName = "username";
String password = "password";
URL url=new URL("http://www.host.com");
Authenticator.setDefault (new MyAuthenticator
(userName,password));
URLConnection uc=url.openConnection();
uc.setAllowUserInteraction(true);
InputStream fi = uc.getInputStream();
}
}
public class MyAuthenticator extends Authenticator {
private java.security.AccessControlContext js=null;
private String userName = null;
private String password = null;
public MyAuthenticator(String userName,String password){
super();
this.userName = userName;
this.password = password;
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication
(userName,password.toCharArray());
}
}