Friday, April 26, 2013

deleting browser cookies (in java)

In our implementation, there's a need for a session cookie that will be created during the user login and that should be deleted during the logout. Everything I read on Google tell the same thing:
  1. Get the cookie object from the request
  2. Set its max age to 0
  3. Add the cookie to the response
This should be quite simple right? But I still see my cookie even if I implement these steps.
After a little bit of search and a little try, I see that I must set cookie path as "/" as well. So the result code is as below. getCookie() takes the cookie from the request object, and deleteCookie() deletes it.

 public Cookie getCookie(HttpServletRequest request, String cookieName) {
  if (request != null && cookieName != null) {
   Cookie[] cookies = request.getCookies();
   if (cookies != null) {
    for (Cookie cookie : cookies) {
     if (cookieName.equals(cookie.getName())) {
      return cookie;
     }
    }
   }
  }
  return null;
 }

 public void deleteCookie(HttpServletRequest request, HttpServletResponse response, String cookieName) {
  Cookie cookie = getCookie(request, cookieName);
  if (cookie != null) {
   cookie.setMaxAge(0);
   cookie.setPath("/");
  }
  response.addCookie(cookie);
 }

Tuesday, December 18, 2012

restore the deleted files in eclipse

I recently did a great job by deleting a class file that's not yet committed to SVN. Thanks to Eclipse I was able to retrieve it using. If you want to restore/undelete files you deleted from Eclipse, all you have to do is to right-click on the folder and choose "Restore from local history".


Wednesday, May 9, 2012

the style 'backgroundalpha' is only supported by type 'mx.controls.textInput' with the theme(s) 'halo'

When I created a new project on Flash Builder 4.5 and imported an old project to this space, I saw that there are a dozen of errors. All of them are "The style 'backgroundAlpha' is only supported by type 'mx.controls.TextInput' with the theme(s) 'halo'". I remember there was no error with the project so I googled to see the problem and it seems like flex does not have this style as of version 4. But our project was in flex 3 and I remember not setting the flex version explicitly when I created the project. Flash builder automatically added this version (flex 4)  to libraries and thus the old project code stopped working. When I switched back to flex 3, it began working again. To achieve this, I clicked on the project > properties > Flex Build Path and chose flex 3.

Thursday, May 3, 2012

packaging with value jar is invalid ?


While trying to build my new project using maven, I got "packaging' with value 'jar' is invalid" error.
I have a parent pom and a separate pom in each modules' folder; but in none of my pom files, I set packaging as "jar".

After googling a little, I saw that the default packaging is "jar" and in the parent pom I didn't specify any packaging type.
So it uses "jar" as packaging type of the parent which is wrong.
After adding "<packaging> pom <packaging>" to my parent pom's attributes, the maven error is gone.

Monday, February 6, 2012

8 reasons for switching to git

Do you use SVN? CVS?
Have you ever heard of GIT? If you want a short but good description why you should use GIT check this link