File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "exception" Watch "exception" New topic
Author

exception

Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 182

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

Joined: Jan 22, 2007
Posts: 196
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

Joined: Feb 28, 2012
Posts: 182

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

Joined: Mar 30, 2012
Posts: 124

the problem is in InfonetFilter.java line number 29, where you are casting into Integer.
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 182

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

Joined: Feb 28, 2012
Posts: 182

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

Joined: Apr 25, 2012
Posts: 4
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

Joined: Feb 28, 2012
Posts: 182

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

Joined: Jan 10, 2002
Posts: 60057
    
  65

Do you really need us to check your spelling?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 182

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
Rancher

Joined: Sep 21, 2011
Posts: 2408
You don't need an alternative to HttpSession, you need to fix whatever problem your code has in using it.
Eshwin Sukhdeve
Ranch Hand

Joined: Mar 15, 2012
Posts: 79
just try with session.putValue() method and get the session value using session.getValue()
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

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

Joined: Jul 18, 2011
Posts: 20
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

Joined: Feb 28, 2012
Posts: 182

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
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Feb 28, 2012
Posts: 182

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

Joined: Jan 08, 2009
Posts: 1398
    
    6



Swastik
avneesh atri
Greenhorn

Joined: Jul 18, 2011
Posts: 20
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
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Feb 28, 2012
Posts: 182

Swastik Dey wrote:

still same problem
not working
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

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

Joined: Jan 08, 2009
Posts: 1398
    
    6

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

Joined: Feb 28, 2012
Posts: 182

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

Joined: Jan 08, 2009
Posts: 1398
    
    6

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

Joined: Feb 28, 2012
Posts: 182

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

Joined: Jan 08, 2009
Posts: 1398
    
    6

Unless you find out what is happening there, it's difficult to resolve the issue.
Pete Nelson
Ranch Hand

Joined: Aug 30, 2010
Posts: 147

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?


OCPJP
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exception
 
Similar Threads
runtime ERROR
An exception occurred processing JSP page
Not able to access default Tomcat home page in Apache Tomcat/6.0.18
Tomcat Hangs during startup
query string variable