开发者

Can I pass complex parameters to a Java Applet?

开发者 https://www.devze.com 2022-12-17 08:33 出处:网络
I\'m really new to Java and I have to create an applet for signing documents electronically. The applet will be called from an ASP.Net web page application.

I'm really new to Java and I have to create an applet for signing documents electronically. The applet will be called from an ASP.Net web page application.

Right now, I embed the applet in page as a <object id="EDOCApplet" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"> and send parameters to the applet like this:

<PARAM id="EdocPath" NAME="EdocPath" value="\\some\where\file.txt" />

In the applet, I can get the value using applet's built-in method getParameter("EdocPath");

What I need is the ability to pass the applet a list of several files and their "display names". For instance, it would be simple to write it down like an XML string:

<DocumentList>
  <UnsignedDocument Path="\\some\wehere\file1.txt" Description="Whatever comes here" />
  <UnsignedDocument Path="\\some\wehere\file2.txt" Description="Something else" />
...

However, as far as I see in HTML4.01 specification, the PARAM HTML element may not have content and it has no end-tag.

The choices I'm considering, are:

  • html-encode the xml structure and send it to applet in a single PARAM object
  • creating a list of PARAM objects and constructing 开发者_运维技巧their names like "File1", "Description1", "File2", "Description2", "File3"... then in Java applet create a while loop to read filenames while there is any.

However, none of the solutions seems to be elegant. The question is, what's the best practice in this case?


Pass them comma-separated:

<param id="files" name="files" 
     value="\\some\where\file.txt,\\some\where\file.txt" />

and then use String.split():

String[] fileNames = param.split(",");

In case of more complex structures you can use JSON to represent them.


You can also provide your applet with a public method:

initFile(String path, String description)

and call this method from javascript code (in which you can loop)

var applet = getElementByTageName(applet);
applet.initFile("yourPath","yourDescription");
0

精彩评论

暂无评论...
验证码 换一张
取 消