Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Session variable error

 
Federico Fna
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all!
My dynamic web project has a java class that captures a session variable with the following code.



If i test the app in local (Mac + Java 1.8 + Tomcat 8) all works. In my remote cloud server (Ubuntu 14.10 + Java 1.8 + Tomcat 8) all works, except this class, that has this code. I copy the complete error here. Note that the row 127 of the error message is the second row of the previous code; and, if i comment this row with // and assign a fix variable all works. So, the problem is that 127^ row.



How can i solve the problem?

Thank in advance!
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


It seems extremely likely that either the getSession() call or the getAttribute() call returns null

If this was my problem I would be instrumenting this section with logging statements.

What exactly is the purpose of the toString() call?

Bill
 
Federico Fna
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank Bill!

Without that .tostring, i see an error message in Eclipse ("cannot convert from object to string).

What i have to do?

Thank you, i'm desperate... :-(

EDIT: note that in my local Mac i've installed Java, JDK and Tomcat; in remote Java (that already include JRE) and Tomcat. But the rest of my application works perfectly! The problem is only that row... Maybe i can try a pair of code rows?

 
Federico Fna
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand the problem! But the reason, no. In my web app there are 2 servlet; first, set the session variable, second, read it. In the up side of both, is the first of my 2 rows ("httpSession...."). What have i done? I've written a simple println command in both classes, that print the session id and after the variable myVar. I post the result!

LOCAL
Both session ID are the same
MyVar printed from the write class "ok"
MyVar printed from the read class "ok"

REMOTE (FROM CATALINA.OUT)
The session ID are different! How is possible it? Same application, same session, 2 servlet, 1^ servlet httpsession... etc give one number, and after few seconds the 2^ servlet with same command give another number of session ID!
MyVar printer from the write class "ok"
MyVar printed from read class null!

Now, i can solve it with a global variable. But i want understand, why it happened in remote this strange situation? Why not in my local server?

Thank all!
 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the session ids are different, hence you are in a different session, therefore you get a null pointer looking at that attribute, because it was stored to a different session.
So the question then is why is the session not being maintained?

Are these two servlets in the same application? "myApp"?
Do you have cookies enabled in your browser?
How are you invoking these servlets?
 
Federico Fna
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes! The question is, why only in remote the session isn't maintained and in local all works.

1) Yes, the 2 servlet are in the same folder in the same application
2) Yes, the cookies are enabled
3) I invoke both from ajax:

FIRST SERVLET (if the user press "login", the jsp page send via ajax all data to SrvUserCheck to verify the data)
titleAjax.open("GET","SrvUserCheck?org=" + org + "&usr=" + usr + "&psw=" + psw + "&scp=" + scp + "&_="+-new Date, false);

AND SECOND SERVLET (if the first servlet return to Ajax "ok", the same Ajax function redirect to servlet SrvPT, to open the intro page)
document.location.href = 'SrvPT?page=intro'

But in local all works perfectly... Maybe a strage setting of the remote Tomcat? :-( Boh
Thank!
 
Federico Fna
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
S O L V E D

Tomcat 8 doesn't accept name of application with "_". I've seen that (only in remote) in the link of app it substitutes the "_" with the corresponding ASCI code and the session doesn't recognize (i don't know the reason). I've tried to re-create my app with another name without "_" and all works fine and the session is recognized.

Thank all!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!