How can I load a Java applet from a dynamic server-side URL?
I want to load an applet from a server side script, eg. a Perl CGI program, etc. Can this be done? how?
<applet code=A21 width=256 height=256 archive="http://url/cgi-bin/test.cgi?R=applet">
thanks in advanc开发者_StackOverflow中文版e for all help.
I haven't done this is a long time (so the security model might have changed on me), but the trick was to configure the server to handle some translation. Say that you have the URL:
http://example.com/applets/MyCode/1.0
You set up the URL translation such that you handle http://example.com/applets with your CGI script, which then gets /MyCode/1.0 as PATH_INFO
. You return whatever you need to return.
Why do you want to do this?
I was able achived this. The mechanism I used was that the cgi script file was wrapped in a shell script. This wrapper calls the cgi script and it would then then embed the original url with a special request in the page it served as the applet. The script would then get run again and detect this special request. It would break without any output but with a return value that the shellscript would catch and output the jar/classfile.
Fetch.sh
run_the_cgi_script.cgi
case $? in
0) #normal script operation without special requests
#do nothing more
;;
1) #a special request that maps to Test3.class
echo "Content-type: application/java-archive"
echo ""
cat ./$myDIR/Test3.class;;
2) #a special request that maps to someclass.class
echo "Content-type: application/java-archive"
echo ""
cat ./$myDIR/someclass.class;;
3) #a special request that maps to somejar.jar
echo "Content-type: application/java-archive"
echo ""
cat ./$myDIR/somejar.jar;;
esac
From the doc:
For security reasons, the applet's class loader can read only from the same codebase from which the applet was started. This means that archives in archiveList must be in the same directory as, or in a subdirectory of, the codebase
so I suspect this will be problematic.
精彩评论