wood burning stoves
The moose likes Servlets and the fly likes How to call a cgi/perl  script from  jsp/java bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to call a cgi/perl  script from  jsp/java bean" Watch "How to call a cgi/perl  script from  jsp/java bean" New topic

How to call a cgi/perl script from jsp/java bean

prakash rm

Joined: May 17, 2001
Posts: 5
I want to call a CGI/perl script from my jsp or java bean . The script is lying on a diferent server . How do i execute the script from my server .
Please help ,
Thanx and regards ,
Vigneshwar kandadi

Joined: Jun 26, 2006
Posts: 2
Hi Prkash,

Have your problem got resolved. i am also same kind of situation.

I also need to call cgi perl script from my java/servelet application get result back to java/servelts.

If your problem got resolved . Could you please help me in this.

Travis Hein
Ranch Hand

Joined: Jun 06, 2006
Posts: 161
I have had this issue once, to read a resource from a different technology from within a servlet filet (or a normal servlet too).
in my case my servlet (filter) needed to call a facility in a proprietary product that was running on the same server, and was also calling JSP based service.
But the concept is the same for your situation, to have a JSP page call the CGI on a different server. Assuming that you can build a URL with get parameters and you are able to interpret the results of the CGI in a meaningful way in your code, this approach may also work for you.

What I did was create an HTTP URL connection from inside my request to physically retreive the HTTP URL request of the other system, and then interpret the results into my handling.

here is a snippet of my code that would make a HTTP URL call out to the other server. I spent most of the time generating the URL to invoke the call and pass parameters from a servlet filter configuration. The resulting page was an XML file, so i stuffed it into an XML parser.

Disclaimer: this solution may be somewhat hackish, but was the best for my situation.
This may have some performance and scaleablility issues with large amounts of users or heavy site loads, as every request that uses it would in turn create a HTTP request to another web server, which causes the original request to block until the nested htttp request is finished.
You may also be able to use a HTTP client toolkit, such as jakarta commons http client instead of the java.net one like I used.

Error: Keyboard not attached. Press F1 to continue.
I agree. Here's the link: http://aspose.com/file-tools
subject: How to call a cgi/perl script from jsp/java bean
It's not a secret anymore!