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.
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 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: 2407
posted
0
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: 78
posted
0
just try with session.putValue() method and get the session value using session.getValue()
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: 18
posted
0
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.
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: 2407
posted
0
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.
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
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: 2407
posted
0
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.
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
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
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.