Invoking ASP from Servlet

Discussions

Web tier: servlets, JSP, Web frameworks: Invoking ASP from Servlet

  1. Invoking ASP from Servlet (4 messages)

    Is it possible to "chain" a request from a servlet to an ASP page so that the invoking browser sees the ASP results? I need to front-end a request in my servlet and pass the call on to an ASP page that is not under my control. The HTTP form request for the ASP page looks something like this:

    <form NAME="gateway" METHOD="POST" ACTION="http://some_other_server.com/ASP_Page.asp">
    <_a href="javascript:document.gateway.submit();">testing</a>
    <input TYPE="HIDDEN" NAME="SecurityFlag" VALUE="mycompany">
    <input type="HIDDEN" NAME="UserName" SIZE="16" MAXLENGTH="20" VALUE="my_UID">
    <input TYPE="HIDDEN" NAME="Password" SIZE="16" MAXLENGTH="20" VALUE="my_pwd">
    </form>

    How do I encode that into a URL object (assuming that's what I need to use)?

    Thanks in advance,
    Kevin

    Threaded Messages (4)

  2. Invoking ASP from Servlet[ Go to top ]

    Since you probably dont want to pass the user/pwd in the URL, you can open a POST URLConnection and send the data over the connection in name/pair values.

    Something like...

    HttpURLConnection server = (HttpURLConnection)new URL("http://some_other_server.com/ASP_Page.asp").openConnection();
    server.setDoOutput(true);
    server.setDoInput(true);
    server.setRequestMethod("POST");

    PrintWriter out = new PrintWriter(server.getOutputStream());
    out.print("SecurityFlag=myCompany&UserName=xx&Password=yy");
    out.flush();

    //Then read the InputStream if you need to get the results from the ASP....

    Hope this helps

  3. Invoking ASP from Servlet[ Go to top ]

    Thanks Weston -- that does help. However, what I really want is for the response from the ASP page to return to the original client browser, because once I pass the login info off, I'm done and out of the picture. From then on it's a conversation between the browser and the application that is hosting that first ASP page.

  4. Invoking ASP from Servlet[ Go to top ]

    It will. You servlet has the response output stream (response.getWriter()), which you can use to send the response from the ASP page to the original client.
  5. Invoking ASP from Servlet[ Go to top ]

    Actually since your invoking the ASP programatically, the data could be sent in the URL as a GET request. I originally pictured the browser showing the data in the URL...but obviously thats not the case.

    Now of course anyone watching network traffic could see the data either way.