Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java IIS Apache
down vote
favorite I folks:
 
I know that CGI is jurassic and before all of you call me lunatic, I must say that this question is only for EDUCATIONAL PURPOSES (in real cases I use JSP).
 
I'm trying to code a "Hello World" CGI in Java, and I'm unsucessful.
 
So I try the same job in C#. Both programs (C# and Java) are totally equal (line by line). The C# works and the Java don't.
 
Here's the code in C#:
 
namespace CGI_CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Content-Type: text/html\n"); // the extra "\n" is needed
            Console.WriteLine("<html>");
            Console.WriteLine("<head>");
            Console.WriteLine("<title>CGI - C#</title>");
            Console.WriteLine("</head>");
            Console.WriteLine("<body>");
 
            Console.WriteLine("<h1>Hello World !</h1>");
 
            Console.WriteLine("</body>");
            Console.WriteLine("<html>");
        }
    }
}
 

In the browser URL I wrote: http://localhost/CGI_CSharp.exe and BINGO! The C# code WORKS !
 
Now the same code in Java:
 

public class CGI_Java
{
    public static void main(String[] args)
    {
        System.out.println ("Content-Type: text/html\n");
        System.out.println ("<html>");
        System.out.println ("<head>");
        System.out.println ("<title>CGI - Java</title>");
        System.out.println ("</head>");
        System.out.println ("<body>");
 
        System.out.println ("<h1>Hello World !</h1>");
 
        System.out.println ("</body>");
        System.out.println ("</html>");
    }
}
 

Now I've tried the URL:
 
http://localhost/java.exe%20CGI_Java
 
(as you know, the %20 is the space => (http://localhost/java.exe CGI_Java)
 
I get:
 
HTTP 404.0 - Not Found
 
So, I try again, now with a batch file (CGI_Java.bat) with a single line of text:
 
java.exe CGI_Java (content of the CGI_Java.bat)
 
And now, I try the URL:
 
http://localhost/CGI_Java.bat
 
Now the browser shows:
 
C:\inetpub\wwwroot>java.exe CGI_Java
 
This is the prompt followed by the command I wrote in the batch file.
 
Can someone help me?
 
Thanks in advance.
Posted 21-Jul-12 0:30am
ppign412
Edited 21-Jul-12 2:42am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Please do not post the same question in multiple forums; you already posted this here[^].
  Permalink  
Comments
ppign at 21-Jul-12 9:00am
   
Sorry for that. I thought the first post was not published, only realized this after submitting the second post. This is my first post in this forum.
Richard MacCutchan at 21-Jul-12 10:09am
   
No worries, I did not check to see whether you were new to the site.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Thank you guys.
 
________________________________________
 
«Água mole em pedra dura, tanto dá até que fura» (Portuguese proverb)
 
«Soft water against hard rock, so much insist until pass through» (free translation)
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 535
1 OriginalGriff 275
2 BillWoodruff 260
3 Shweta N Mishra 244
4 Deepu S Nair 230
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,818
2 DamithSL 4,958
3 Manas Bhardwaj 4,539
4 Maciej Los 3,755


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 22 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100