Solved

Java and CGI-Programs

Posted on 1997-10-20
8
281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

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 …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

696 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