Monday, June 30, 2008

Pass data structure from PHP to JS

In JS:

var ap_radioMode = unserialize('<?php echo serialize ($ap_radioMode) ?>');

i.e. Use PHP's serialze() and echo out the value, then apply JS's counterpart unserialize() to get the data structure.

Sunday, June 15, 2008


Cookie is sent from web server to the browser as a header, and it is stored in the browser. On all the subsequent requests, the browser would send the cookie data transparently to the server, So it advised to keep the size minimal.

Http Session data is stored in the server, but its session identifier is sent in cookie. In this way, the session reference is passed instead of the actual data to save network traffic. When the user disable the cookie in the browser, URL rewrite (response.encodeUrl) will be used to append jsessionid on url parameters.

When a GET hits the server with no session cookie or id, Tomcat creates a new session and sets the cookie:
Set-Cookie: JSESSIONID=2978A7FABFF3DB35BE622290E1294CDE; Path=/
It then also encodes all URLs on a page with jsessionid. At this point, does not know if the browser supports cookies. So the next GET (with both cookie and URL parameter) is required to decide if cookies are OK or not.

Thursday, June 5, 2008

Is RMIRegistry a JNDI service provider?

The JNDI architecture consists of an API and a service provider interface (SPI). Java applications use the JNDI API to access a variety of naming and directory services. The SPI enables a variety of naming and directory services to be plugged in transparently.RMIRegistry is also one type of JNDI provider besides Ldap, File System.

envs.put(Context.PROVIDER_URL, "rmi://localhost:1099");

RegistryContextFactory implements getInitialContext() method.JNDI provides a naming context, which is a a set of name-to-object bindings. All naming operations are relative to a context.A name that is bound within a context is the JNDI name of the object. A Context object provides the methods for binding names to objects, unbinding names from objects, renaming objects, and listing the bindings.

File System: file name -> file (accessed via file handler)
DNS: machine name -> IP
LDAP: Ldap name -> Ldap entry

The Initial Context
In the JNDI, all naming and directory operations are performed relative to a context. There are no absolute roots. Therefore the JNDI defines an initial context, InitialContext(in the API reference documentation), which provides a starting point for naming and directory operations. Once you have an initial context, you can use it to look up other contexts and objects.When the initial context is constructed, its environment is initialized with properties defined in the environment parameter passed to the constructor, and in any application resource files.

JNDI determines each property's value by merging the values from the following two sources, in order:

1. The first occurrence of the property from the constructor's environment parameter and (for appropriate properties) the applet parameters and system properties.
2. The application resource files (