aspose file tools*
The moose likes Servlets and the fly likes servlet calling perl script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet calling perl script" Watch "servlet calling perl script" New topic
Author

servlet calling perl script

adam braunton
Greenhorn

Joined: Mar 22, 2002
Posts: 7
I have to invoke a simple Perl script using a servlet, but to be honest I don't have a clue where to start. Any thoughts would be much appreciated!
Mayer Salzer
Greenhorn

Joined: Apr 01, 2002
Posts: 20
I would start by trying to redirect the servlet-request to your cgi script.
In your "service" method:
response.sendRedirect("/cgi-bin/yourScriptName");


Sun Certified Programmer for Java 2 Platform
adam braunton
Greenhorn

Joined: Mar 22, 2002
Posts: 7
Yes, i tried the sendRedirect, but the poblem is that this has the same effect as calling the Perl script directly on the server. However, the WebSphere server does not recognise the MIME type of the script, and prompts the user to download the script, rather than running it!

I need a way of calling the script directly from Java, i.e. Acting like a Broker servlet - because I don't fancy rewriting it!
[ June 07, 2002: Message edited by: adam braunton ]
Mayer Salzer
Greenhorn

Joined: Apr 01, 2002
Posts: 20
I'm not sure why that's happening. I tried an example like that myself and it works fine.
When you redirect, a message is sent to the client (your browser) telling it to send the request elsewhere. Provided that you redirect to the appropriate path of your cgi-bin (or whatever else runs your script), your websphere server should be out of the loop at that point. . .
For example suppose you have a servlet "TestServlet" invoked with "http://yourhost/webapp/TestServlet". You also have a cgi script named "script.cgi" invoked with "http://yourhost/cgi-bin/script.cgi". In the servlet, if you call response.sendRedirect("http://yourhost/cgi-bin/script.cgi") it will redirect the request to the new url which happens to be your cgi script. The fact that the request was rerouted from a websphere server (or any other) should not matter.
adam braunton
Greenhorn

Joined: Mar 22, 2002
Posts: 7
The problem is, that if i type the URL (http://www....) to the Perl script directly into the browser, i will be promted to download rather than the script executing. But if i type the URL as a location to the server (http://localmachine3/.....) the script executes. So i take it that a sendRedirect basically does the same thing as the former method. I need a way to force the script to execute, if possible. without moving the script from the cgi-bin folder....?
Tracey Currier
Ranch Hand

Joined: Feb 06, 2001
Posts: 50

I got this to work by setting
res.setContentType("text/plain")
then using the redirect to my url.
My url was to a perl script that was
loaded with parameters, worked ok
behind the firewall
The perl script output an html page
and I sent the html header out in the
perl script


MS,MS,SCJP,SCBCD Seize the day!
 
Don't get me started about those stupid light bulbs.
 
subject: servlet calling perl script