• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

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.  
0
gans
Asked:
gans
1 Solution
 
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now