Cookie
request parameter.In your HTML applet code, just add the document's cookie as a parameter. (Note that I'm writing the HTML applet code in JavaScript to dynamically get the document's cookie.)
<script language="JavaScript" type="text/javascript">
<!--
document.write("<embed");
document.write("name='MyApplet'");
document.write("type='application/x-java-applet;version=1.6'");
document.write("code='org/puguasoft/examples/MyApplet.class'");
document.write("codebase='/applets/'");
document.write("browserCookie='" + document.cookie + "'");
document.write("</embed>");
-->
</script>
Then in your servlet, use the browserCookie
parameter value as the Cookie
property in the HttpServletRequest.import javax.swing.JApplet;
import java.net.URL;
import java.net.URLConnection;
public class MyApplet extends JApplet{
public void doIt(URL url){
URLConnection urlConnection = url.openConnection();
String cookie = getParameter("browserCookie");
urlConn.setRequestProperty("Cookie", cookie);
urlConnection.connect();
// Now you can do what you need with the URLConnection
// (e.g. open up an InputStream to read the data)
// using the same cookie session.
}
}
For more information check out these postings:
- http://developer.apple.com/qa/qa2001/qa1265.html
- http://sourceforge.net/tracker/index.php?func=detail&aid=1414542&group_id=107955&atid=649116
- http://lists.apple.com/archives/Java-dev/2006/Mar/msg00278.html
- http://sourceforge.net/forum/forum.php?thread_id=1298604&forum_id=371125
- http://sourceforge.net/forum/forum.php?thread_id=1634825&forum_id=371124
1 comment:
This is cool!
Post a Comment