JSP and JavaBean problem.......

Hai.. everyone...

I have a problem about the javaBean and jsp, pls help me to solve this probem ... ...

my problem is i create a jsp program let say counter.jsp.... this .jsp function is to call another javaBean (Counter.java ) function which will holds the current numbers of times the bean 's property has been accessed.

My problem is WHY when i open 1browser to access this counter.jsp file.. it work fine... it will show the output like ::

you access this page for 1time;

you access this page for 2time;

you access this page for 3time;

you access this page for 4time;

but what happen is when i open another diffrent browser to access the same page at the SAME time it will show the output like :

you access this page for 5time;

you access this page for 6time;

you access this page for 7time;

you access this page for 8time;

but i expert the output will like that same value like

you access this page for 1time;

you access this page for 2time;

you access this page for 3time;

you access this page for 4time;

WHY the value in not started from begining , is that the value store in the Bean is not clear before i access the SAME pages AT the SAME timeS?

Then how can i solve this type of problem using javaBean to made the counter.jsp can handle many user at 1 time....

pls help and Thnaks a lot......

[1433 byte] By [ZeroPassOnea] at [2007-10-2 13:11:35]
# 1

You have not included any code, so I am using my mind reading powers to aid you. However they are not that reliable. Next time post some code.

>WHY the value in not started from begining

Currently it sounds like you just have it declared via <%! int counter = 0; %> on the page. This sort of declaration is not thread safe, and it is shared by all users of the JSP page.

You want each user to have an individual counter?

That means that you have to store each persons count in their own individual session. - ie make the counter bean a session attribute, and create one for each individual user.

public class Counter{

int count = 0;

public void visit(){

count++;

}

public int getCount(){

return count;

}

}

And then in the jsp:

<jsp:useBean id="counter" type="com.mypackage.Counter" scope="session"/>

<% counter.visit() %>

Cheers,

evnafets

evnafetsa at 2007-7-13 10:39:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...