Someone recently reported that when cookies are disabled and J2EE session is enabled, his sessions are not maintained in case of POST request. As per that, CF or rather the app server always creates a new session everytime. His code looked like
<form method="post" action="test.cfm?#session.urltoken#"> ... <input type="submit" value="Submit" > </form>
can you see whats wrong with above code?
As per the Servlet spec of J2EE, when cookies are disabled, session is maintained by url rewriting and that is done by appending ‘;jsessionid=’ to the URI. Note the semicolon ‘;’ before ‘jsessionid’.
In the above code, it is appending session.urltoken which looks like ‘CFID=1600&CFTOKEN=59663989&jsessionid=2830a9edcf6f794ff481′. Therefore the url becomes “test.cfm?CFID=1600&CFTOKEN=59663989&jsessionid=2830a9edcf6f794ff481″ whereas it should been like “test.cfm;jsessionid=2830a9edcf6f794ff481?CFID=1600&CFTOKEN=59663989″. Since jsessionId is not correctly specified, server does not get this and hence creates a new session.
So how do you handle it? One way is to get the sessionId and urltoken from the session and create the url as expected (which is some effort on developer part). Alternatively, you can use a rather simple approach of using URLSessionFormat(url) which will do the exact thing which is required here. URLSessionFormat() appends the necessary information if cookies are disabled. If they are enabled, it does not do anything. Therefore it might be a better idea to always use this function for any GET or POST url.
The above code should actually have been
<cfset myurl=URLSessionFormat("test.cfm")>
<form method="post" action="#myurl#">
...
<input type="submit" value="Submit" >
</form>
