Wednesday, December 28, 2005

Spring MVC RedirectView appends jsessionid

Back when I worked at Sun we used to have a shutdown period the last two weeks of the year. I'm not sure if they still have that policy but I wonder why all companies don't operate like that. This time of year most people are either on vacation or are in vacation mode while at work. In fact, most large projects are not considered or launched until the new year anyway.

I work at a pretty small shop and it's like that for us too. I had a day free before going on vacation so I volunteered to fix a couple of minor bugs. One of them dealt with removing a ;jsessionid=????? that was being appended to one of our links. If you're not familiar with what that is, it's basically tomcat's way of tracking sessions when a user does not have cookies enabled. Instead of storing it in a cookie, that string is passed around in the URL. But in order to see the jessionid string in the first place, it needs to be enabled somewhere in your code.

One method is using c:url tags in your jsp pages. Another is by using HttpServletResponse's encodeURL or encodeRedirectURL methods in your controller code. Usually it's a good idea to include these calls but in our webapp we do not store session data and that string was just adding extra noise since the page where it appeared is used as a launchpad to forward to a perl page.

My first intuition was to look for the c:out tag but no luck there so I searched for the encodeURL methods. luck there either. Where could this be coming from? I then saw a call to spring mvc's RedirctView class so I figured it might be in there. The docs made no mention of jsessionid's so I looked at the source code. A ha...RedirectView actually calls encodeURL before the redirect so that was the culprit. Another one of the many benefits of open source...full source code view.

I described the problem to Andy and he showed me how to easily view a library's source code in IDEA. If you go to your preferences and then look at the libraries in your project, you can add an entry point to the src code on your local machine. The same goes for api's too. The best thing about it is that you can keep it in the zip file and IDEA will still find it.

1 comment:

Anonymous said...

good info. It would be better if you give a solution clearly.