>>> Mahesh Davendran <[EMAIL PROTECTED]> 01-Jun-01 5:30:39 PM >>>
>Thanks very much for the fast response Nic,

That's okay. Apparently others on this list don't appreciate such
help (you know who you are).


>In that case, How is the option 2 done. How to use
>the CGIServlets in calling the cgi scripts. It would be
>excellent if you could give me an example or a URL
>to find it. Thanks.

I don't have a URL off hand but if you do a google search for:

  CGIServlet

If you go through Sun's documentation you'll probably find something
because Sun used to support this  for Java Webserver (don't know if
they still do).

It's pretty simple to write a CGIServlet if you can't find one. You
just need to be able to call a script to fire off the CGI program with
the correct environment.

The easiest way to do that is to write a native script that creates
the CGI environment from it's command line parameters. A MyCGIServlet
might then do this:

public class MyCGIServlet
extends HttpServlet
{
   public void doGet(HttpSer....
   throws ...
   {
       Runtime rt=Runtime.getRuntime();
       String[] env=new String[...];
       env[0]="REQUEST_METHOD=GET";
       env[1]="PATH_TRANSLATED="+docroot+request.getRequestURI());
       env[2]="QUERY_STRING="+request.getQueryString());
       Process cgiScript=rt.exec("cgiscript.sh",env);
       OutputStream out=response.getOutputStream();
       cgiOutput=cgiScript.getInputStream();
       byte[] buf=new byte[5000];
       int red=cgiOutput.read(buf,0,5000);
      while(red>-1)
       {
           out.write(buf,0,red);
           red=cgiOutput.read(buf,0,5000);
       }
       out.close();
    }
}


Simple eh?

The docroot BTW is to allow you to locate the CGI document base
anywhere you want.


Nic

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to