<p>前面说得不清楚,下面重新来一遍。<br>
<font color="#FF8080">One:</font>如果你的JDK是1.2.2以上(应该没问题吧)以上,请找到c:/jdk/jre/lib/jaws.jar<br>
将其添加入classpath.因为其中含有packge:netscape.javascript.Jsobject <br>
<font color="#FF8080">VJ我没用过,我想它加入packge的功能还是应该有。:</font><br>
<font color="#0080FF">Two:</font>写你的HTML文件,用Javascript写两个方法分别写cookie和读cookie,下面附带一个例子<br>
&lt;html&gt;<br>
<br>
&lt;head&gt;<br>
&lt;title&gt;Testing&lt;/title&gt;<br>
&lt;script&gt;<br>
<br>
function setCookie(txt){<br>
document.cookie = txt;<br>
alert (&quot;Setting cookie : &quot;
+ txt);<br>
}<br>
<br>
function getCookie(){<br>
var cookieAfter =do
cument.cookie;<br>
alert (&quot;Getting the cookie : &quot;
+ cookieAfter);<br>
return cookieAfter;<br>
}<br>
<br>
&lt;/script&gt;<br>
&lt;/head&gt;<br>
<br>
&lt;!-- The MAYSCRIPT attribute is required in order for the Java methods to be available
to the JavaScript functions. --&gt;<br>
&lt;applet code=&quot;cakk.class&quot;
Width=400 Height=50 MAYSCRIPT&gt;<br>
&lt;/applet&gt;<br>
<br>
&lt;/html&gt;<br>
<br>
<font color="#80FF00">Three:</font>编写你的Applet,示例如下:<br>
//Title: JavatoJs<br>
//Version: 1.0<br>
//Copyright: Copyright (c) eguy<br>
//Author: eguy<br>
//Company:<br>
//Description:<br>
import java.awt.*;<br>
import java.awt.event.*;<br>
import java.applet.*;<br>
import netscape.javascript.JSObject;
<br>
<br>
public class cakk extends Applet {<br>
JSObject win;<br>
boolean isStandalone = false;<br>
TextField setck = new TextField();<br>
TextField getck = new TextField();<br>
Button button1 = new Button();<br>
Button button2 = new Button();<br>
GridLayout gridLayout1 = new GridLayout();<br>
<br>
//Get a parameter value<br>
public String getParameter(String key, String def) {<br>
return isStandalone ? System.getProperty(key, def) :<br>
(getParameter(key) != null ? getParameter(key) : def);<br>
}<br>
<br>
//Construct the applet<br>
public cakk() {<br>
}<br>
<br>
//Initialize the applet<br>
public void init() {<br>
try {<br>
jbInit();<br>
}<br>
catch(Exception e) {<br>
e.printStackTrace();<br>
}<br>
}<br>
<br>
//Component initialization<br>
private void jbInit() throws Exception {<br>
try{<br>
win = JSObject.getWindow(this);<br>
}catch (Exception e){<br>
//do
n't throw exception information away, print it.<br>
e.printStackTrace();<br>
}<br>
<br>
&nbsp;&nbsp;&nbsp;
setck.setText(&quot;Set cookie&quot
;<br>
this.setLayout(gridLayout1);<br>
getck.setText(&quot;Get cookie&quot
;<br>
button1.setLabel(&quot;Set&quot
;<br>
button1.addActionListener(new java.awt.event.ActionListener() {<br>
<br>
public void actionPerformed(ActionEvent e) {<br>
button1_actionPerformed(e);<br>
}<br>
});<br>
button2.setLabel(&quot;Get&quot
;<br>
button2.addActionListener(new java.awt.event.ActionListener() {<br>
<br>
public void actionPerformed(ActionEvent e) {<br>
button2_actionPerformed(e);<br>
}<br>
});<br>
this.add(setck, null);<br>
this.add(button1, null);<br>
this.add(getck, null);<br>
this.add(button2, null);<br>
}<br>
<br>
//Start the applet<br>
public void start() {<br>
}<br>
<br>
//Stop the applet<br>
public void stop() {<br>
}<br>
<br>
//Destroy the applet<br>
public void destroy() {<br>
}<br>
<br>
//Get Applet information<br>
public String getAppletInfo() {<br>
return &quot;Applet Information&quot;;<br>
}<br>
<br>
//Get parameter info<br>
public String[][] getParameterInfo() {<br>
return null;<br>
}<br>
<br>
void button1_actionPerformed(ActionEvent e) {<br>
String msg[];<br>
msg = new String[1];<br>
<br>
// Create a local copy of the cookie text<br>
msg[0] = setck.getText();<br>
<br>
// Call the JavaScript function to set the cookie <br>
win.call(&quot;setCookie&quot;, msg);<br>
<br>
}<br>
<br>
void button2_actionPerformed(ActionEvent e) {<br>
<br>
String txt = (String)win.call(&quot;getCookie&quot;,null);<br>
getck.setText(txt);<br>
}<br>
}<br>
<font color="#FF8080">Four:这里Cookie的写入和读出均较简单,仅是测试。复杂的根据自己要求写吧。</font></p>