Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpURLConnection.

 
Kumar Nat
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Th ebelow code is part of an applet. I'm trying to use the method below to
1. connect to the url
2. re-use an existing session
3. and let the response be displayed in the parent window that launched this applet window.
I'm fine with step3 to use showDocument. I wanted to know how to achieve steps 1 and 2. I'm new to applet programming.
Please Help.

private void accountLookup(String accountNumber)
{
//logger.debug("Entered accountLookup()");

//build url
webServerStr = "http://" + hostName + ":" + port + servletPath;
sessionId = getParameter("sessionId");
try
{

webServerStr = webServerStr + "?serverip=" + localip;
webServerStr = webServerStr + "&clientip=" + remoteip;
webServerStr = webServerStr + "&accountNumber=" + accountNumber;

// connect to the servlet
URL url = new URL( webServerStr );

HttpURLConnection connection = (HttpURLConnection) url.openConnection();


if(sessionId != null) {
connection.setRequestProperty("Cookie", sessionId);
}

connection.setDoInput(true);
connection.setDoOutput(true);

connection.setDefaultUseCaches (false);
connection.setUseCaches (false);

connection.setRequestMethod("GET");
connection.connect();

AppletContext context = getAppletContext();

context.showDocument(url);
}
catch (Exception e)
{
System.out.println("in accountLookup: " + e.getMessage());
e.printStackTrace();
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic