Friday, October 24, 2008

Sharing Java Applet Sessions in Firefox

There is a known problem in JEP (Java Embedding Plugin) for Firefox in which new sessions (or no sessions at all) are used for every new Java applet request to a servlet. This can be problematic for applets that requests data or URL from a servlet requiring authentication or a login. To get around this problem, you can pass in the current HTLM document's cookie as a Java applet parameter, and then use the cookie in the HttpServletRequest's 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:


Friday, October 10, 2008

Detecting Browser Java Version Using Javascript

Trying to detect a client's browser for the installed Java plugin version and whether or not it's installed, can be a real pain. Luckily,Eric Gerds has created a JavaScript library to do just that. The JavaScript can detect the version of the Java plugin, if any, on different browsers including FireFox, Internet Explorer, Safari, and Opera. In addtion, his script can also detect QuickTime, Flash, Windows Media Player, and many other browser plugins.

Check out the PluginDetect JavaScript: http://www.pinlady.net/PluginDetect/

Tuesday, August 26, 2008

Automount External USB Hard Drive in SuSE 10.3

To automount an external USB hdd in OpenSuSE 10.3 and up, just follow these simple instructions:

First, create a new directory to mount the external HDD:
mkdir /media/usb-hdd
Next, modify /ets/fstab to include a new label entry for the external HDD. You can label it anything you want without spaces.
LABEL=YOUR-HDD-LABEL /media/usb-hdd ext3 auto,nofail,defaults 1 2
Finally, create a script in /etc/udev/rules.d/ called 99-mount.rules containing the following command:
#run mount -a everytime a block device is added/removed
SUBSYSTEM=="block", run+="/bin/mount -a"
Now, whenever you boot into OpenSuSE, the external USB hdd labeled YOUR-HDD-LABEL will be automatically mounted.

Monday, August 25, 2008

Mounting USF/USF2 BSD Filesystem in Ubuntu Linux

Ubuntu only supports read-only of BSD filesystems (USF/USF2). To mount the disk just issue the command:
mount -r -t ufs -o ufstype=44bsd /dev/yourdevice /mnt/destination


Thursday, July 03, 2008

Getting a List of Installed System Fonts in Java

Previously, you could get a list of fonts installed in the running system by using using the Java AWT Toolkit:
Toolkit tk = Toolkit.getDefaultToolkit();
String[] fontNames = tk.getFontList();
However, the Toolkit.getDefaultToolkit() method has been deprecated in favor of the java.awt.GraphicsEnvironment. The GraphicsEnvironment class describes the collection of java.awt.GraphicsDevice objects and java.awt.Font objects available to a Java application on a particular platform.

To get a list of font names installed on the system, just use the the getLocalGraphicsEnvironment() method:
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
String[] fontnames = ge.getAvailableFontFamilyNames();
There are many other usefull methods in GraphicsEnvironment class, for more information, take a look at the API.