Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Session.getAttribute gets Null in Servlet

888525Oct 27 2011 — edited Nov 1 2011
I 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?
This post has been answered by maheshguruswamy on Oct 28 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 29 2011
Added on Oct 27 2011
24 comments
7,930 views