Java and CGI-Programs

Hallo,
I want to send my CGI-Program some parameters with a Java-applet. When the Java-applet run on the Internet-Explorer 3.0 and higher, I can send the parameters without any problems. But when I use the Netscape 3.0 or higher I get a IOExeption with the failure: "URL doesn't support output". To build a connection I use the following program:
url = new URL(CGIProgram);
urlConnection = url.openConnection();
outStream = new PrintStream(urlConnection.getOutputStream());
outStream.print("COMMAND=" + CommandChoose + "&" + "USERIDENTIFYER=" + UserIdentifyer + "&" + "CHOOSEBOX=" + Choosebox + "&" + "SEARCHFIELD=" + "&" + Encoder.encode(InputField) + "&" + "SEARCHNAME=" + URLEncoder.encode(FieldInput) +      SearchString.toString());
outStream.close();
inputStream = new InputStream(urlConnection.getInputStream());
while ((type = inputStream.readLine()) != null)
{
      s.append(type);
}
inputStream.close();

Which people can say me, what I must do, that this program can run on Netscape, too.  
gansAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

remboCommented:


What you really want to do is pass those options as
part of your URL connection, so:


                     url = new URL(CGIProgram "COMMAND=" + CommandChoose + "&" + "USERIDENTIFYER=" +
                     UserIdentifyer + "&" + "CHOOSEBOX=" + Choosebox + "&" + "SEARCHFIELD=" + "&" +
                     Encoder.encode(InputField) + "&" + "SEARCHNAME=" + URLEncoder.encode(FieldInput)
                     + SearchString.toString());

urlConnection = url.openConnection();
                     outStream = new PrintStream(urlConnection.getOutputStream());

This should work in *any* browser.  Make the parameters
part of your initial URL specification and you avoid the
problems with how CGI params get sent.

Hope that helps,

-Tony

0
gansAuthor Commented:
Hallo Tony,

thanky you first for your help. But when I use your suggestion, the compiler say, that he found an error in "url = new URL(CGIProgram "COMMAND...."). And when I write an "+" between CGIProgram and "COMMAND..." or an "+" and a "?" and then run the applet, the CGI-Program don't become any Input, but the applet an IOExeption after outStream.close(). Please say me what is wrong!
0
eugenemCommented:
May be you forget last '/' in CGIProgram?
0
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

remboCommented:

Sorry about the mistake, you definitely need the
+.  Go ahead and print the statement that you're
calling (use System.out.println to print the same
thing that you're sending to the URL call, post it
here and I can tell you what is wrong.

Or, just e-mail it to rembo@cks.com

-Tony
0
gansAuthor Commented:
Hi Tony,

you've wrote me, that I should send you the URL-String, which I write
into the URL-function:
http://jupiter/scripts/cgi_bin/dwcgidef.exe COMMAND=8& USERIDENTIFYER=28073457&CHOOSEBOX=0x00000000&SEARCHFIELD=Partner%3a&SEARCHNAME=Gans

Please say me what's wrong.
0
remboCommented:
url = new URL(CGIProgram + "?" +"COMMAND=" + CommandChoose + "&" + "USERIDENTIFYER=" +
                     UserIdentifyer + "&" + "CHOOSEBOX=" + Choosebox + "&" + "SEARCHFIELD=" + "&" +
                     Encoder.encode(InputField) + "&" + "SEARCHNAME=" + URLEncoder.encode(FieldInput)
                     + SearchString.toString());

You need that "?" after the CGIPROGRAM.  

-Tony


0
gansAuthor Commented:
Hi Tony,

thank you for your help, but it haven't solve my problem. Because I have the same problems as before I change my code. The Java-Program run in the Internet-Explorer without any problems and in the Netscape it doesn't open a connection to my CGI-Program. It beep only one time and then I get an IOExeption.
Do you have any idear now?
0
kollegovCommented:
All you need is

url = new URL(CGIProgram);
urlConnection = url.openConnection();
url.setDoOutput(true)

It drive me nuts once too :)
But with setDoOutput all work :)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.