Solved

Java and CGI-Programs

Posted on 1997-10-20
8
280 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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 60 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 96
stackato and cloud 4 85
rhino JavaScript import, load 25 82
windows explorer path to command prompt 5 43
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

785 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