Guneet's Web Log

August 9, 2008

request.getSession (false) always returning a session

Filed under: Java, work — Tags: , , , — guneetsahai @ 3:14 am

Recently I found that request.getSession (false) was *always* returning a session instance even when it is not created earlier by my application. After spending 2-3 hours on it, I figured out the cause. Read on …….

I am working on adding a rather unique jobs functionality for chahiye.info which required an authentication mechanism. For this purpose, I wanted to add a check at various pages to ensure that if a session did not exist a request to these pages would be re-directed to loign page. This was done using the following code

HttpSession session = request.getSession (false);
if (session == null)
{
// forward request to login page
// return;
}

However to my surprise this api was always giving me a session instance even when I had not explicitly created one (after the login request). I searched my entire code base & confirmed that I was not creating a session anywhere. Looked up the JavaDoc for this method in class javax.servlet.HttpServletRequest, which clearly stated that if the supplied boolean is false and if the request has no valid HttpSession, this method would return null.

After spending some more time, I realized the problem. Basically if the application is using a JSP, the container (in my case Tomcat 5.5) by default ends up creating a session. In my case, the user’s landing page itself was a JSP as a result the session gets created at that time itself. To avoid this, simply add the following directive at your JSP, which tells the JSP compiler not to use session variable in the compiled class.

< % @page session="false" % >

Note – You will have to get rid of extra spaces between “<”, “%” & “@” symbols.

Have you also had a similar situation and figured out another cause for this? If yes, please share your experience here.

August 3, 2008

IIS Does not start – Skype may be the culprit

Filed under: software — Tags: , — guneetsahai @ 8:40 pm

I come from Java world but was recently trying my hand at IIS. I wanted to learn how easy or difficult is to deploy a simple website on it. During the process faced a problem and figured out the cause, which I think is worth sharing. Read on …….

I was basically following an online tutorial here. Unfortunately after installing IIS on my win xp pro box, I could not confirm that it was running – When I pointed my web browser to http://localhost the default page did not show up. As a matter of fact nothing happened. I did not get any error message, just a simple white screen – I tried with Firefox (my default browser) as well as IE 7.

After reading some more, I found out about the IIS Management Console. Through it, I could see that the “Default Website” on my IIS installation wasn’t started and any attempt to start it would result in “Unexpected Error” window as shown on the right. I had no clue what was going wrong. Tried re-installing IIS but didn’t help.

Next while going through the properties of “Default Website” I realized that it works on port 80. Tried to change it (I thought that maybe the firewall might be causing some havoc) to 8080 and VOILA it worked. Only if the error message could be more meaningful it would have saved me a an hour or two.

Next I Tried disabling Firewall but it didn’t help. Executed the following command on command prompt to find that some process was indeed listening on port 80.

d:\>netstat -a | find “LISTENING”
TCP nucleo-01:ftp nucleo-01:0 LISTENING
TCP nucleo-01:smtp nucleo-01:0 LISTENING
TCP nucleo-01:http nucleo-01:0 LISTENING
TCP nucleo-01:epmap nucleo-01:0 LISTENING
TCP nucleo-01:https nucleo-01:0 LISTENING
TCP nucleo-01:microsoft-ds nucleo-01:0 LISTENING
TCP nucleo-01:1025 nucleo-01:0 LISTENING
TCP nucleo-01:35048 nucleo-01:0 LISTENING
TCP nucleo-01:1026 nucleo-01:0 LISTENING
TCP nucleo-01:netbios-ssn nucleo-01:0 LISTENING

Had a look at my processes but didn’t see any apparent process (Apache or something like that) so decided to kill processes one by one. My first shot was at Outlook (didn’t help), next came various IMs – That one helped. I was able to start IIS after killing Skype, Yahoo & GTalk on its regular port 80.

I later managed to zero in on skype and found that it was indeed running on port 80. On checking up its configuration (Tools -> Options -> Advanced -> Connection) found an option to stop using port 80 & 443. Restarting skype after disabling the use of standard http & https ports solved my problem.

I’m still new to MS world & in the process of learning so wonder if there is something else missing/incorrect on/with my machine configuration. Why wouldn’t a simple error (like port busy or something) be shown otherwise?

Have you faced this problem too and have something to share, please let me know.

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.