occasionally it seems that from within our action classes calls to request.getSession() return a null value. Now, if a session hasn't already been established then that's expected behavior. However, we're getting this error after a session has definitely been established. Has anyone seen similar behavior or know why this is happening and how to prevent it?
We're also seeing Servlet exceptions in our JSPs complaining about beans not being found in any scope. The action classes are putting beans into request scope for the pages to use. If the user hits "refresh", magically the bean is found. This is a sporadic error. We know that the name of the attribute is correct in the request object.
request.getSession() should always return a session because it will create a new one if one does not already exist.
It is possible for request.getSession(false) to return null because the false denotes to not create a new session if one does not already exist.
Your second issue I could see happen if validation failed on a page because there would no longer be a bean in request scope if you return directly to a page.
A good workman is known by his tools.
Joined: Aug 23, 2002
We're just calling request.getSession() and it is most definitely returning null (but only occasionally. The same action object will work fine and handle plenty of requests correctly, then all of a sudden it appears unable to find the session object).
On the second case there is no validation as there's nothing to validate. We're simply taking a DTO, calling request.setAttribute("blah", blah); and forwarding to the correct JSP. The JSP is unable to find bean "blah" in any scope. If you hit refresh, voila, the bean is magically there.
These are definitely sporadic problems. The same JSP finds the bean most of the time. Based on the other problem I'm inclined to thing that it's the request object in the action class that's causing the problems. I believe the JSP when it says it can't find the object.
It may be possible that something strange is going on in the server that is killing off sessions. I'm still sticking with saying request.getSession() will never return null. It might be returning a session but the session is getting killed off while you are trying to do something meaningful with it. request.getSession() might even throw a NullPointerException if the request is getting killed off before calling the method on it.
I think issue #2 is closely related to #1. This might be a server configuration issue. It certainly does not sound like something caused by Struts.
Joined: Aug 23, 2002
Hmmm. I wonder if it has anything to do with Tomcat being embedded in JBoss. We never same the request.getSession() = null before we did that. The missing beans is something that we did see before. The question is what configuration setting(s) would even affect this?