How to get url of redirected page?
<p>I need to develop Java application for registration on some web-service. There is the code:</p>

<pre><code>    URL url=new URL("xxx");
    URLConnection connection=url.openConnection();
    connection.setDoOutput(true);
    PrintWriter out=new PrintWriter(connection.getOutputStream());
    out.print("first_name="+"abc");
    out.print("&amp;");
    out.print("last_name="+"abc");
    out.print("&amp;");
    out.print("user_email="+"email);
    out.print("&amp;");
    out.print("user_pass="+"pass");
    out.print("&amp;");
    out.print("user_phone="+"phone");
    out.print("&amp;");
    out.print("user_address="+"address");
    out.print("&amp;");
    out.print("user_city="+"city");
    out.print("&amp;");
    out.print("user_state="+"state");
    out.print("&amp;");
    out.print("user_zip="+"zip");
    out.print("&amp;");
    out.print("submit="+"1");
    out.close();
    Scanner in=new Scanner(connection.getInputStream());
    StringBuilder builder=new StringBuilder();
    while (in.hasNextLine()) {
        builder.append(in.nextLine());
        builder.append("\n");
    }
    in.close();
    System.out.println(builder.toString());
</code></pre>

<p>This code works and returns to me a message about successful registration. But a script with message is another script which is redirected page from page with for for registration, and I need to get its url. So, please, tell me, how can I do it?</p>
