Here is the trick of implementing a perl script output and a servlet based output on a browser.
create frames or IFRAMES for this, and give the proper source in <src=”your resource”> tag of frame, iframes.
so now you can obtain the response from both the things…
Filed under: Apache, CGI, my research
February 27, 2007 • 1:29 pm
.. if you’ve only got a little CGI traffic, you can serve CGI scripts through Tomcat. How?
1. Alter Tomcat’s conf/web.xml file
a) There’s a CGIServlet that’s commented out; remove the comments so that the live file contains.
Code:
<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>6</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi</param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>
|
|
b) Associate URLs cgi-bin with the CGI Servlet.
Code:
<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>
|
|
2. Rename the CGI jars supplied with (but disabled) in Tomcat
Code:
cd /usr/local/tomcat/server/lib
mv servlets-ssi.renametojar servlets-ssi.jar
mv servlets-cgi.renametojar servlets-cgi.jar
|
|
3. In your webapps/xxxx/WEB-INF folder, add a new directory called cgi and place your CGI script in there. Example content:
Code:
#!/usr/bin/perl
print (“Content-type: text/html\n\n”);
$now = localtime();
print <<”STUFF”;
<html>
<head><title>Wow!</title></head>
<body bgcolor=green text=white>
This is going to look naff at $now
</body>
</html>
STUFF
|
|
And mark this file executable
Then restart Tomcat to ensure it’s picked up the new, global, web.xml file.
Note – this example is written with exact details for Tomcat 5.5.9, Apache 2.0.54 and Fedora Core 3 Linus.
Thanks WHC
Filed under: Apache, CGI