• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
sumanta panda
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kindly also advise me if my logic is wrong in my code accoding to my requiremt.
 
sumanta panda
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear ChrisSir,
The scope of the cmp varibale is int type;
int cmp=0;int total=0;int cmp_temp;

Regards
Sumanta
 
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chris meant session scope or application scope etc!
 
sumanta panda
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic