Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

How do I write a CGI in JAVA

  Asked By: Sunil    Date: Jul 01    Category: Java    Views: 5955

I am trying to learn how to write a CGI. To me that means the program stays on
the server, runs on the server, and use the server's files instead of the PC
where the Web page is being viewed.

This type of program should be so common (all your search engines, all shopping
carts and anything else of a commerical nature) must be CGIs. Any JAVA
programmer who is getting paid (as a JAVA programmer) should know how to write
this type of program.
JAVA must have a very easy way to do this. If I want to write a windows program
I extend a FRAME. If I want to put that program into my web page I extend an
APPLET. So what do I extend to create a CGI?

To me this should be a simple question because everyone who is working as a
JAVA programmer must be writting CGI programs. How else do you take data, typed
into a web page at the users PC, and put it into a file on the server? How do
present data from a server file into a web page (such as a the results of a

I am sorry if I have rambled, but I must be having trouble wording this
question correctly because the light hasn't turned on yet. This has got to be a
simple thing and it has to be in the Sun JAVA API package.



5 Answers Found

Answer #1    Answered By: Jet Brown     Answered On: Jul 01

Take a look at the J2EE tutorial on sun's website.
Naybe this will help you.

Answer #2    Answered By: Ludkhannah Fischer     Answered On: Jul 01

Although that is the industral strength answer.
I did see something that looked intresting called a servlets.

Answer #3    Answered By: Sairish Kauser     Answered On: Jul 01

Look into JSP's also......................

Answer #4    Answered By: Javairea Akram     Answered On: Jul 01

CGI stands for common  Gateway Interface. Mainly, this is a technology that
allows you to take some information from the client, make some processing and
return some results  to the client. All the above things are achieved by writing
a CGI script. This is an (almost) ordinary program, which can be written in ANY
language (C++ and Perl are the most used). This script runs  on a single machine
(the server), so it doesn't need portability. Instead, the speed is critical, so
Java might not be the best solution to write  it. Anyway, it can be done in Java

So, the client passes the request to the server  by sending several parameters
(name-value pairs) in two basic ways:
- by query string (the parameters are appended to the URL)
- by environment variables (the parameters are encapsulated in the body of
the HTTP request)

Either way, when you write the script (a Java program  in your case), you will
read the parameters, take the needed actions and than respond to the client
request, most commonly by producing an output for the browser.

Now, if you'll read the first one or two chapters from any CGI book, you will
learn how to do it (at least for the simpler and more common things).

Answer #5    Answered By: Laura Rodriguez     Answered On: Jul 01

Thanks this is the best answer so far.
I am in the process of installing J2EE but it did seam to be a sledge hammer
approach to an simple

Didn't find what you were looking for? Find more on How do I write a CGI in JAVA Or get search suggestion and latest updates.