• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Session and NullPointerException! URGENT!

 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using Jrun and Apache on solaris. The code below works perfect in a windows environment. But in the unix environment, I am getting NullpointerException since the session is null. But if I go back(browser back button) and come back, there is no problem. It is showing the following pages. In the example, pageid is a name given for each page. login page, accounts page, reports page etc. created by the out.println statements(not jsp).
Could anybody help please....urgent!
Part of the servlet code is.....
if (pageID.equals("Login"))
{
if (userExists) {//2
if (retrievedPassword.equals(password)) {
..........

try{
UserView userView = new UserView(userName,password);
session=request.getSession(true);
session.putValue("userView", userView);
.......
........
else if(pageID.equals("accounts"))
{
session=request.getSession(false);
if(session==null){
response.sendRedirect("/html/login.htm");
}
if (session !=null){
UserView userView= (UserView)session.getValue("userView");
if(userView== null){
response.sendRedirect("/html/login.htm");
}
else{
System.out.println("user logged in");
}
.......
..........
else if(pageID.equals("reports"))
{
........
........
}
Thanks
Beksy
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you check your code see before you call request.getSession() , did you call any method on response, in another word
To make sure the session is properly maintained, you must call getSession() before the response is committed.
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The same code works okay in windowsNT. Does it make any difference?
 
wenwei cheng
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know, but sometimes it does make difference. I guest depends on the implement of the server, I did not use JRun. But for iPlanet, my co-worker did encounter some problem with deferent platform.
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the answer. The problem is like this. When I user enters, he enters his username and password. After validation(session created), he will be taken to the accounts page. This part is working okay. when he select an account, it should display the reports page. Instead it is going to the login page implying that session is null. I don't know why? But if the user selects the browser back button comes back without logging in, he can see account numbers and go to the reports page without any problem. Thereafter until he logs out, he can go back and forth without any problem. Why is he losing the session only at the first page(accounts->reports)? And why only in the unix platform(apache and jrun)?
No problem with Apache and jrun on windows NT(default configuration)
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anybody have an answer for me. I am using JRun 2.3.3
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow. Still don't have an answer?
Hmmm...by any chance are you using a session cookie for anything?
What type of app is your login?

Originally posted by Beksy Kurian:
Anybody have an answer for me. I am using JRun 2.3.3


 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jason,Thanks for the reply. I tried to give some system.out.println and got these strange results. In JRUN of windowsNT platform, I am getting the same session if I do like the following...
else if(pageID.equals("accounts"))
{
System.out.println(session.getId()); //first message- brings the
//session id same as the one when they login
session=request.getSession(false);
System.out.println(session.getId()); //2nd message-appends
//a '==' sign with the session id only in Unix platform
System.out.println(session.getId());
if(session==null){
response.sendRedirect("/html/login.htm");
}
if (session !=null){
UserView userView= (UserView)session.getValue("userView");
if(userView== null){
response.sendRedirect("/html/login.htm");
}

//But in Unix platform, it is getting the correct session id before the request.getsession(false). And it is appending an equal sign to the session id if I put the message after the request.getsession(false). So it thinks that it is a new session(even if the user is coming for the first time after login) and redirects to the login page again. But only for the first time. If he goes back and come again, session id becomes the same and the user can browse through all pages.
Any clues yet?Appreciate an answer
Beksy
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What browser are you suing when you get have this problem? The reason I ask is that we had a very similar problem. After a succesful login in the user is unable to access the next page ( as though not logged in ).
We did not find the root of the problem as only one person experienced this using Netscape and when that person upgraded to Netsape Navigator 4.77 he did not have that problem anymore.
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using IE 5.01 and netscape 4.77 and opera on unix. Same browsers if they are connecting to windows2000 JRUN configuration faces NO problem.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
don't forget to check and see if the string your camparing with the .equals() is null before you do the comparison. I was developing locally without checking for this and then when I deployed I got null pointer exceptions all over the place
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't quite get it.
{
System.out.println(session.getId()); //same session id (1)session=request.getSession(false);
System.out.println(session.getId()); //appends '=' with id(2)
}
For eg: for the first message, I am getting '9679' session id
For 2nd message, it is '=9679'. Where is this '=' sign coming from?
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oops! request.getSession(false)
was not supposed to be the part of the comment in the above post
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Macromedia just informed that there is a bug associated with JDK 1.2.2 and JRun 2.3.3. I may have to install JDK 1.3.1 or upgrade to JRun 3.1
Thanks to all
Beksy
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We had 1.3.0 JDK which we were using with tomcat. Then when we installed JRun and jdk 1.2.2, we forgot to remove jdk 1.3.0 from the classpath even though we added jdk 1.2.2 to the classpath. Since 1.3.0 was the first line in the classpath, it was still pointing to JDK 1.3.0. JDK 1.3.0 has the bug. Macromedia informed me that they have seen the same problem with Jrun 2.3.3 too eventhough that was not the actual cause of our problem.
The discussion with JRun can be seen in the following link http://forums.allaire.com/jrun/messageview.cfm?catid=67&threadid=212573
Thanks
Beksy
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic