• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exception

 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my all transactions within pages are working when i am performing once but when again i give url to run the page or refresh my page to run again it is giving following error

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.ClassCastException: java.lang.Integer
InfonetFilter.doFilter(InfonetFilter.java:29)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.
Apache Tomcat/6.0.18



what is it.
to run my program again i have to restart my computer.
 
Piyush Mangal
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to run my program again i have to restart my computer.
Do you really have to restart your machine? I think you meant restarting your tomcat server. The issue is ClassCastException.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piyush Mangal wrote:
to run my program again i have to restart my computer.
Do you really have to restart your machine? I think you meant restarting your tomcat server. The issue is ClassCastException.


actualy i am working on my college server so i can't restart server so i have to restart the computer to restart server

why this exception is coming.
is there any problem in code?
 
Anurag Verma
Ranch Hand
Posts: 168
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the problem is in InfonetFilter.java line number 29, where you are casting into Integer.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anurag Verma wrote:the problem is in InfonetFilter.java line number 29, where you are casting into Integer.


is there is any problem in the session in my first servlet i am setting session like following



and in my second servlet i am getting session like following
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Megha Singhal wrote:
Anurag Verma wrote:the problem is in InfonetFilter.java line number 29, where you are casting into Integer.


is there is any problem in the session in my first servlet i am setting session like following



and in my second servlet i am getting session like following

please tell me how can i maintain session from one servlet to another, i have done through above method but its not working.
 
sanket singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paste line 29 of InfonetFilter.java
and
try to change your second servlet to
int ccno=Integer.parstInt(session.getAttribute("ccno"));

i think it might work.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sanket singh wrote:Paste line 29 of InfonetFilter.java
and
try to change your second servlet to
int ccno=Integer.parstInt(session.getAttribute("ccno"));

i think it might work.


this is giving me following error

Ben.java:25: cannot find symbol
symbol : method parstInt(java.lang.Object)
location: class java.lang.Integer
int ccno=Integer.parstInt(session.getAttribute("ccno"));
^
1 error
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you really need us to check your spelling?
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Do you really need us to check your spelling?

sorry i didn't observe that.
i correct it but it is still giving error.
actualy waht i observe is that http session is not working on my server, when i trying to redirect to any jsp or any other servlet page it is still giving the same error and when i diasabled those line where i made httpsession in first servlet its redirecting to any of the page.
so is there is any alternative of http session to make session for the integer variable.
 
Tim Moores
Bartender
Posts: 2895
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need an alternative to HttpSession, you need to fix whatever problem your code has in using it.
 
Eshwin Sukhdeve
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just try with session.putValue() method and get the session value using session.getValue()
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eshwin Sukhdeve wrote:just try with session.putValue() method and get the session value using session.getValue()

Those methods are deprecated and should not be used. See the HttpSession.
 
avneesh atri
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Megha Singhal wrote:
Bear Bibeault wrote:Do you really need us to check your spelling?

sorry i didn't observe that.
i correct it but it is still giving error.
actualy waht i observe is that http session is not working on my server, when i trying to redirect to any jsp or any other servlet page it is still giving the same error and when i diasabled those line where i made httpsession in first servlet its redirecting to any of the page.
so is there is any alternative of http session to make session for the integer variable.


if you are using this line of code
"int ccno=Integer.parseInt(session.getAttribute("ccno")); "

then it will through an exception at runtime because in method parseInt ,argument has to be a string not a int or Integer or anything else.
So make sure when you are setting an attribute in the session it must be of type Integer and when you are using getAttribute() method, type cast it to Integer , as the return type of this method is Object.
If you do this it will surely work.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
avneesh atri wrote:
Megha Singhal wrote:
Bear Bibeault wrote:Do you really need us to check your spelling?

sorry i didn't observe that.
i correct it but it is still giving error.
actualy waht i observe is that http session is not working on my server, when i trying to redirect to any jsp or any other servlet page it is still giving the same error and when i diasabled those line where i made httpsession in first servlet its redirecting to any of the page.
so is there is any alternative of http session to make session for the integer variable.


if you are using this line of code
"int ccno=Integer.parseInt(session.getAttribute("ccno")); "

then it will through an exception at runtime because in method parseInt ,argument has to be a string not a int or Integer or anything else.
So make sure when you are setting an attribute in the session it must be of type Integer and when you are using getAttribute() method, type cast it to Integer , as the return type of this method is Object.
If you do this it will surely work.

if i am doing that as per you are saying it is giving following error

Ben.java:28: incompatible types
found : java.lang.Object
required: int
int ccno=session.getAttribute("ccno");
^
1 error

 
Tim Moores
Bartender
Posts: 2895
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the javadocs of HttpSession to find out what data type HttpSession.getAttribute returns. You seem to have removed a critical piece that was present in your earlier code.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:Read the javadocs of HttpSession to find out what data type HttpSession.getAttribute returns. You seem to have removed a critical piece that was present in your earlier code.

it is saying "Returns the object bound with the specified name in this session" so in my code it should return int value
so if i am doing following

then it is giving following compilation error

Ben.java:28: incompatible types
found : java.lang.Object
required: int
int ccno =session.getAttribute("ccno");
^
1 error

 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
avneesh atri
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Megha Singhal wrote:
avneesh atri wrote:
Megha Singhal wrote:
Bear Bibeault wrote:Do you really need us to check your spelling?

sorry i didn't observe that.
i correct it but it is still giving error.
actualy waht i observe is that http session is not working on my server, when i trying to redirect to any jsp or any other servlet page it is still giving the same error and when i diasabled those line where i made httpsession in first servlet its redirecting to any of the page.
so is there is any alternative of http session to make session for the integer variable.


if you are using this line of code
"int ccno=Integer.parseInt(session.getAttribute("ccno")); "

then it will through an exception at runtime because in method parseInt ,argument has to be a string not a int or Integer or anything else.
So make sure when you are setting an attribute in the session it must be of type Integer and when you are using getAttribute() method, type cast it to Integer , as the return type of this method is Object.
If you do this it will surely work.

if i am doing that as per you are saying it is giving following error

Ben.java:28: incompatible types
found : java.lang.Object
required: int
int ccno=session.getAttribute("ccno");
^
1 error




This is because you are not type casting it to Integer class. I think i have mentioned that in my post . try it ,it will work
 
Tim Moores
Bartender
Posts: 2895
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Megha Singhal wrote:
Tim Moores wrote:Read the javadocs of HttpSession to find out what data type HttpSession.getAttribute returns. You seem to have removed a critical piece that was present in your earlier code.

it is saying "Returns the object bound with the specified name in this session" so in my code it should return int value

No, the method signature specifically says that it returns java.lang.Object. So if you want to use it as anything other than an Object you need to typecast it.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Dey wrote:

still same problem
not working
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Megha Singhal wrote:
Swastik Dey wrote:

still same problem
not working

That's not a cast. Although it would still probably work if the attribute was an Integer value.

The important thing is to work out exactly what session.getAttribute("ccno") is returning. Get your code to print out or log the value and the type, and that
 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly do you mean by not working? Throwing any exception? Make sure that you are getting the value in the session scoped variable ccno.


 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:
Megha Singhal wrote:
Swastik Dey wrote:

still same problem
not working

That's not a cast. Although it would still probably work if the attribute was an Integer value.

The important thing is to work out exactly what session.getAttribute("ccno") is returning. Get your code to print out or log the value and the type, and that


my first servlet is following


then i am calling following servlet

and i am getting value on this page
my next servlet is following

on this page i am getting following error

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.ClassCastException: java.lang.Integer
InfonetFilter.doFilter(InfonetFilter.java:29)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.18

 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the log stack trace it seems that you don't have exception in any of the above two codes.

java.lang.ClassCastException: java.lang.Integer
InfonetFilter.doFilter(InfonetFilter.java:29)


rather in a file InfonetFilter.java. What code do you have in that file in line number 29?
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Dey wrote:From the log stack trace it seems that you don't have exception in any of the above two codes.

java.lang.ClassCastException: java.lang.Integer
InfonetFilter.doFilter(InfonetFilter.java:29)


rather in a file InfonetFilter.java. What code do you have in that file in line number 29?


i don't have that java file. that is might be on the server.
 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you find out what is happening there, it's difficult to resolve the issue.
 
Pete Nelson
Ranch Hand
Posts: 147
Debian Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are getting confused by the objects being returned from session.getAttribute(String). Every item returned by the getAttribute method is an instance of java.lang.Object. When you cast it, you need to cast it back to the same type it was before you added it to the session (with session.setAttribute(String, Object)).

In your case, you are adding an int primitive type, which gets automatically "upgraded" to an Integer (because we need a java.lang.Object, not a primitive type).

At this point, you've added an Integer object to your session. Why bother casting or converting to a String, just to get it's primitive int value? Can't you cast to the Integer object, and then get the int value from that Integer Object?

Also, I notice that when people suggest you "cast" your Object to something else, you are instead calling a method like the Object's .toString(). I just have to ask - are you familiar with casting in Java?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic