Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Java and CGI-Programs

Posted on 1997-10-20
8
Medium Priority
?
282 Views
Last Modified: 2012-06-27
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
Comment
Question by:gans
8 Comments
 
LVL 4

Expert Comment

by:rembo
ID: 1229235


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
 

Author Comment

by:gans
ID: 1229236
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
 
LVL 3

Expert Comment

by:eugenem
ID: 1229237
May be you forget last '/' in CGIProgram?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:rembo
ID: 1229238

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
 

Author Comment

by:gans
ID: 1229239
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
 
LVL 4

Expert Comment

by:rembo
ID: 1229240
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
 

Author Comment

by:gans
ID: 1229241
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
 
LVL 10

Accepted Solution

by:
kollegov earned 120 total points
ID: 1229242
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question