i have a java applet in a form like following
$form['applet'] = array(
'#prefix' => '&开发者_StackOverflowlt;div>',
'#markup' => '<p align=center>
<applet codebase="." code="Clock.class" width=170 height=150>
</applet>
</p>',
'#suffix' => '</div>',
);
where should i place Clock.class
file such that drupal always loads it.Something to do with base_path
function.
If there are other classes and resources that need to be loaded, you probably want to replace the '.' for the codebase with the path to that directory instead of changing the path to the .class file.
Assuming your class file is part of a module in a subfolder applet, something like this should work:
... codebase = "' . drupal_get_path('module', 'yourmodule') . '/applet/" code...
(not sure if the trailing slash is necessary)
That HTML would make the JRE expect to find the class in the same directory as the web page.
I'm not familiar with applets. But if you need to make an absolute path to it, you should place it in the module creating the form and use drupal_get_path
.
In code this would look like this:
$path = drupal_get_path('module', 'MODULE_NAME');
$form['applet'] = array(
'#prefix' => '<div>',
'#markup' => '<p align=center>
<applet codebase="'$path'" code="Clock.class" width=170 height=150>
</applet>
</p>',
'#suffix' => '</div>',
);
Using the above code, you need to place the applet in the root of your custom module. You could also make a subfolder for you applet and place it there if you like. The latter is the most drupal way of doing it, but I tend to only create subfolders if I more than 3-5 files in a module.
精彩评论