Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. CGI in Java - Legacy but interesting (for educational purposes)

CGI in Java - Legacy but interesting (for educational purposes)

Scheduled Pinned Locked Moved Web Development
javaquestioncsharphtmlhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    ppign
    wrote on last edited by
    #1

    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 CGI\_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.

    T 1 Reply Last reply
    0
    • P ppign

      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 CGI\_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.

      T Offline
      T Offline
      Trak4Net
      wrote on last edited by
      #2

      With the batch file maybe redirecting the output? http://www.robvanderwoude.com/battech_redirection.php[^] Interesting topic, I imagine you are getting the 404 because you are expecting the CGI_Java to be passed as a command line argument. I don't think the browser works that way. Have never tried anything like this but wonder if any querystring variables would be passed as command args like... http://localhost/java.exe?CGI\_Java :~ ???

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups