Session.getAttribute gets Null in Servlet
888525Oct 27 2011 — edited Nov 1 2011I have just upgraded from Java 1.5.0_06 to 1.6.0_27 ,and Weblogic from 9.1 to 10.3.5 .Java EE from 1.4 to 1.5
In my Servlet testServlet.java,session.getAttribute(loginId)
gets null at a particular time.I have the application running with old versions as well on a seperate machine and it works fine there.Its after the update ,this problem is coming up?
Can anyone helpme to resolve this.The reason for session.getattribe is null?
below is just a test small sample servlet code.
public class Testervlet extends HttpServlet
{
private static final String LOGIN = "LoginId";
private static final String SERVER = "Server";
private static final String DATABASE= "Database";
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
HttpSession session = req.getSession(false);
if( session == null )
{
session = req.getSession(true);
session.setMaxInactiveInterval(2000)
}
if(session!=null)
{
synchronized (session) {
String loginId= (String)req.getParameter(LOGIN );
if( loginId!= null )
{
session.setAttribute(LOGIN, loginId);
}
System.out.println("LogonNAme is "+session.getAttribute(LOGIN));
String server = (String)req.getParameter(SERVER)
JDBC.setServer(server);
String db = (String)req.getParameter(DATABASE);
JDBC.setDB(db);
testMethod(req, res, session);
}
}
else
System.out.println("error");
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
doPost(req, res);
}
testMethod(req,response,session)
{
Do some stuf....
}
}
This servlet is called each time user wants to connect.We are not using connection pooling.Each user has a seperate connection.
Session.getAttribute
System.out.println("LogonNAme is "+session.getAttribute(LOGIN));
gets null .I am just not able to figure out whats the reason.Can anyone please help me .Is it becaiuse of jdbc connections or drivers or Weblogic?