Friday, October 30, 2009

Q&A



[ Team LiB ]





Q&A


Q1:

I stored data in a session; why can't I find it in the session object?


A1:

There are many possible reasons for this. The most common problem is that you mistyped the name of the item you wanted to retrieve. You might have stored it as name and you are trying to retrieve it as Name. If possible, create a Java class that contains a number of public static final string constants defining the names of the items you want to store in the session, and use these constants instead of hard-coding strings into the servlets and JSPs. Another possibility for this problem is that the browser has cookies disabled. Make sure you have cookies enabled or that you use URL rewriting to pass the session ID along.

Q2:

Why do I get a compile error when I retrieve an item from a session?


A2:

The session.getAttribute method returns items of type Object. Even if you store a String object or another type, the return value is always Object. You must cast the result to the appropriate type when you retrieve it from the session.

Q3:

I turned off cookies in Internet Explorer; why don't I see the session ID when I use URL rewriting?


A3:

Make sure you have turned off cookies for the security zone you are using. If you are accessing your local machine, you need to change the security setting for the Local Intranet zone, at least if you use http://localhost as the first part of your URL. Internet Explorer does not always notice that a URL is really part of the local intranet, however. It may consider http://localhost as being in the local domain, and think that http://zinger.wutka.com is in the Internet zone, even though it is the same machine as localhost. Try setting the security for the Internet and Local Intranet zones to be High.

Q4:

Why does the browser seem to lose the session ID when I navigate through my site using URL rewriting?


A4:

The problem is most likely the presence of an HTML page somewhere along the way. For URL rewriting to work, you must rewrite the URL for every link the browser might access. You must convert any static HTML pages into JSPs, changing the hyperlinks so that they use the URL rewriting routines.






    [ Team LiB ]



    No comments: