jQuery in Action, 2nd edition*
The moose likes Servlets and the fly likes Session value is not reflection properly for view the page in next time in post login Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session value is not reflection properly for view the page in next time in post login" Watch "Session value is not reflection properly for view the page in next time in post login" New topic
Author

Session value is not reflection properly for view the page in next time in post login

sumanta panda
Ranch Hand

Joined: Jun 23, 2008
Posts: 224
Dear Sir,
I am setting the value in my java file(UserAuthentication.java
session.setAttribute("cmpValue",new Integer(myInt));.
I am using pagging concept.
Session is mentitained from login to Logout.

Sir i am facing the problem that when i going to calulate Total cmp
by using pagination concept it is calculated for Total cmp value perfectly
for the first time in all page.If again i view the page and select the page
then Total cmp is doubled and also triple for next and next.Onless i am not logout, the session value will not set to zero for each view request.
When i logout then login the session value start with 0 and it will increment cmp value and calculate it in paging concept.
But if again i viewed and using paging concept the it will add previous session value let say 3200+new value in all paging 3200=6400.
Here i should display 3200 in my output.bUT I AM GETTING 6400.

Kindly sir advise me for the needful.

I WISH YOU VERY HAPPY NEW YEAR TO ALL MY JAVARANCH SUPPORT TEAM.

Thanks and Regards
Sumanta Panda

if( session.getAttribute("cmpValue")!=null && session.getAttribute("cmvValue")!=null)
{

int cmp_temp=Integer.parseInt((String)inVec.elementAt(3));
cmp=cmp+cmp_temp;

}
Integer totalcmp=(Integer)session.getAttribute("cmpValue");
totalcmpdata= totalcmp.intValue()+cmp;
session.setAttribute("cmpValue",new Integer (totalcmpdata));
sumanta panda
Ranch Hand

Joined: Jun 23, 2008
Posts: 224
Sir i am facing the problem in session that every time after login
for each request the session value is repetated.But if it logout and login
for first time value comming properly.From second time of new request onwards value is become doubled for every request.

Please advise me for the needful.

Thanks and Regards
Sumanta Panda
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Please explain what it is you really want. You say that you have a value in the session, that the value is maintained for as long as the session is maintained. This is exactly what is supposed to happen. If you don't want the value maintained for the entire session then you should not use the session to store the value.

If you want a value to exist only for a single request then use the request to store the value instead of the session.

If you need the value stored for multiple requests but don't want it to accumulate then over-write the value when you want it to reset to zero, that is, instead of doing:

do:


This may not be what you want, if it is not then please provide more details.


Steve
sumanta panda
Ranch Hand

Joined: Jun 23, 2008
Posts: 224
Dear Sir,
After login in the form successfully then the form data is comming.
In the form when we view the data then accoding to the filter
data is displaying in the second form.In the second form we are using paging concept.

So when login and then view and i am using paging concept then
the value of cmp in each page is calculated.

For example accodring to logic

After view then click next for paging the record
In paging concept cmp=cmp of paga1value+ cmp of paga2value+cmp of paga3value=let say 3200 which value i have stored in totalcmpdata.

Sir ACCODING TO YOUR ADVISE IF I PASS ONLY CMP VALUE THEN WHAT
only last page cmp value is displaying..

My requiremnt is if it is within the pagination the The total cmp value calculated.
Once the page completed TotalCMP Value displayed right for the first time.

If that same page again i view then result is comming 6400 not 3200
Means sir previous is storing 3200+Again 3200=6400/wrong.

But if i logout and login and check first time it is working.

If same page i click the view again use paging concept value
is Totalcmp=old value+Totalnew All pagingvalue.
It should be like Totalcmp=Totalnew All pagingvalue;


It is bit difficult me to explain you.But sir if you are able to understand
my requirement kindly please advise me.

Thanks for your quick response and support.

Regards
Sumanta Panda
sumanta panda
Ranch Hand

Joined: Jun 23, 2008
Posts: 224
Kindly also advise me if my logic is wrong in my code accoding to my requiremt.
sumanta panda
Ranch Hand

Joined: Jun 23, 2008
Posts: 224
After the login first time if I click the view page
x.jsp
View->Button

x.jsp(Frame2)
Cmp cmv(Record)
12
22
Next->Buttion(Paging concept) (Let say Page1 cmp VALUE(3)+PAGE2 CMPVALUE(5)
Total Cmp=8.
----------------------------------------

If I view the page second time
x.jsp
View->Button

x.jsp(Frame2)
Cmp cmv(Record)
12
22
Next->Buttion(Paging concept) (Let say Page1 cmp VALUE(3)+PAGE2 CMPVALUE(5)
Total Cmp=16.// Which is wrong I should getting here also 8)

-------------------------------------------------------------
If I view the page third time
x.jsp
View->Button

x.jsp(Frame2)
Cmp cmv(Record)
12
22
Next->Buttion(Paging concept) (Let say Page1 cmp VALUE(3)+PAGE2 CMPVALUE(5)
Total Cmp=24.// Which is wrong I should getting here also 8)
---------------------------------------------------
Kindly advise me for the needful.

Thanks and Regards
Sumanta Panda
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Hi Sumanta,

I am sorry, but I still can't grasp what the problem you are having, or what you expect to happen that isn't happening. The only think I can suggest is that you read some other paging resources, such as This one from the JavaRanch FAQ. There are plenty of pre-made tags that can help you, usually with examples provided, such as this one from jsptags, or this one from the servletsuite.com.
Chris Paulraj
Greenhorn

Joined: Oct 14, 2007
Posts: 7
Sumantha, What is the scope of the variable "cmp"? Where is it being declared?

int cmp_temp=Integer.parseInt((String)inVec.elementAt(3));
cmp=cmp+cmp_temp;
sumanta panda
Ranch Hand

Joined: Jun 23, 2008
Posts: 224
Dear ChrisSir,
The scope of the cmp varibale is int type;
int cmp=0;int total=0;int cmp_temp;

Regards
Sumanta
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 823

Chris meant session scope or application scope etc!


Regards, Sud.
SCJP 5 ScjpFAQ JLS
sumanta panda
Ranch Hand

Joined: Jun 23, 2008
Posts: 224
Dear SudiptSir/ChrisSir,

i using scope="session".Could you Please guide me where i did the mistake in my code.


int cmp=0;,int cmp_temp=0;int totalcmpdata=0;

if( session.getAttribute("cmpValue")!=null && session.getAttribute("cmvValue")!=null)
{

int cmp_temp=Integer.parseInt((String)inVec.elementAt(3));
cmp=cmp+cmp_temp;

}
Integer totalcmp=(Integer)session.getAttribute("cmpValue");
totalcmpdata= totalcmp.intValue()+cmp;
session.setAttribute("cmpValue",new Integer (totalcmpdata));


x.jsp
View->Button

x.jsp(Frame2)
Cmp cmv(Record)
1 2
2 2
Next->Buttion(Paging concept) (Let say Page1 cmp VALUE(3)+PAGE2 CMPVALUE(5)
Total Cmp=8.
----------------------------------------

If I view the page second time
x.jsp
View->Button

x.jsp(Frame2)
Cmp cmv(Record)
1 2
2 2
Next->Buttion(Paging concept) (Let say Page1 cmp VALUE(3)+PAGE2 CMPVALUE(5)
Total Cmp=16.// Which is wrong I should getting here also 8)

-------------------------------------------------------------
If I view the page third time
x.jsp
View->Button

x.jsp(Frame2)
Cmp cmv(Record)
1 2
2 2
Next->Buttion(Paging concept) (Let say Page1 cmp VALUE(3)+PAGE2 CMPVALUE(5)
Total Cmp=24.// Which is wrong I should getting here also 8)


Thnaks in Advance.

Regards
Sumanta Panda
sumanta panda
Ranch Hand

Joined: Jun 23, 2008
Posts: 224
Dear SudiptSir/ChrisSir,

i using scope="session".Could you Please guide me where i did the mistake in my code.


int cmp=0;,int cmp_temp=0;int totalcmpdata=0;

if( session.getAttribute("cmpValue")!=null && session.getAttribute("cmvValue")!=null)
{

int cmp_temp=Integer.parseInt((String)inVec.elementAt(3));
cmp=cmp+cmp_temp;

}
Integer totalcmp=(Integer)session.getAttribute("cmpValue");
totalcmpdata= totalcmp.intValue()+cmp;
session.setAttribute("cmpValue",new Integer (totalcmpdata));


x.jsp
View->Button

x.jsp(Frame2)
Cmp cmv(Record)
1 2
2 2
Next->Buttion(Paging concept) (Let say Page1 cmp VALUE(3)+PAGE2 CMPVALUE(5)
Total Cmp=8.
----------------------------------------

If I view the page second time
x.jsp
View->Button

x.jsp(Frame2)
Cmp cmv(Record)
1 2
2 2
Next->Buttion(Paging concept) (Let say Page1 cmp VALUE(3)+PAGE2 CMPVALUE(5)
Total Cmp=16.// Which is wrong I should getting here also 8)

-------------------------------------------------------------
If I view the page third time
x.jsp
View->Button

x.jsp(Frame2)
Cmp cmv(Record)
1 2
2 2
Next->Buttion(Paging concept) (Let say Page1 cmp VALUE(3)+PAGE2 CMPVALUE(5)
Total Cmp=24.// Which is wrong I should getting here also 8)


Thnaks in Advance.

Regards
Sumanta Panda
Chris Paulraj
Greenhorn

Joined: Oct 14, 2007
Posts: 7
Sumanta, It looks like a logic issue, cmp should always be zero for every POST, so I don't see any reason on why it's added cumulatively? it should work, if you reinitialize cmp=0 after adding to totalcmp!

int cmp_temp=Integer.parseInt((String)inVec.elementAt(3));
cmp=cmp+cmp_temp;

}
Integer totalcmp=(Integer)session.getAttribute("cmpValue");
totalcmpdata= totalcmp.intValue()+cmp;
--> Add the below line
cmp=0
sumanta panda
Ranch Hand

Joined: Jun 23, 2008
Posts: 224
Dear CrisSir,
I have changed according to your advise.
I feel that my logic is bit wrong.I tried a lot to change my logic.
But i didnt solve it.Could you please rectify my logic so that it will work.

Thanks in Advance.

Regards
Sumanta Panda
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Session value is not reflection properly for view the page in next time in post login