Sunday, November 29, 2009

Applet Caching not working

If your applet always downloads the jar even though jar is cached, Make sure you have not disabled the URLConnection's caching via the API: URLConnection.setUseCaches and URLConnection.SetDefaultUseCaches.

ImageIcon's underlying mechanism for fetching the resource is a URLConnection. Calling URLConnection.setDefaultUseCaches(false), sets a "part of the static state of all URLConnections" which cause the JRE to ignore the cache and redownload the entire jar every time it accessed. Simply removing all instances of setDefaultUseCaches will solve the problem.

http://java.sun.com/j2se/1.5.0/docs/guide/plugin/developer_guide/applet_caching.html

Sunday, May 10, 2009

Not enough storage is available to complete this operation

In IE createStyleSheet throws javascript error Not "enough storage is available to complete this operation".

document.createStyleSheet(cssfile);

To handle it swallow javascript error by catching exception.

try {
    document.createStyleSheet(cssfile)
} catch(e) {}

Saturday, April 25, 2009

Clear session on Browser Close

In web application, it is common that user sign in, do some work and close browser(By clicking X) with doing proper Sign Out. In such case, user session is still active and will be cleared only after specified session out period. If the specified timeout is small than it should not be problem. But if specified timeout is long in that case it is important to clear user session on browser close becuase clearing session on server will remove unused objects from server and hence reduce memory leak.

Here is possible solutions to handle it.

1) One approach is to use frames in your application. After user Sign In, Load application in Frameset as below.


<FRAMESET rows="0, *" onbeforeunload="javascript:callServer()">
<FRAME src="sessionFrame"> // Blank frame unloaded when browser close.
<FRAME src="mainFrame"> // Your Application pages
</FRAMESET>



When user closes browser(By clicking X), it will unload frameset and call callServer() javascript function. In callServer() function make server call(using XMLHttpRequest or submit Html Form) to clear session.

ORM Framework for Kotlin

In Kotlin, ORM (Object-Relational Mapping) libraries provide a convenient way to interact with databases using object-oriented programming p...