File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes JSP synchronization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP synchronization" Watch "JSP synchronization" New topic

JSP synchronization

Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
In a JSP file I have a customerID which is stored in a session. This customerID I use to recieve (select only) some customer information from a database, through a java class. I have doubt about if there can be any synchronization problems, if more users is accessing the page the same time, and i.e. CUSTOMER A is recieving CUSTOMER B�s information and visa versa?

//In the jsp page, this method call the java class to select data from database
user.dataObject.User obj_user = obj_order.getCustomerInformation( customerID );

//Here I get the customer Name in the jsp page
String customerName = obj_user.getCustomerName();

Is it necessary to synchronize the method, which do the select query in the Java class to avoid that CUSTOMER A is recieving CUSTOMER B�s information?
[ November 30, 2005: Message edited by: Jeppe Fjord ]
C Broussard

Joined: Jun 18, 2004
Posts: 28
couple things to keep in mind.. in your javabean obj_order.getCustomerInformation() make sure you're doing a "new" object creation so that each jsp call gets a new memory location. if you merely reuse a class variable or a static instance of that then you will have data corruption. assuming that's not the problem, as long as the variable is in session scope you theorectically shouldn't have to worry about customer b accessing customer a stuff.

it's kinda hard to tell from your code that you've posted.
Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
Here is my code from the java bean:

Here I get the customerID from a session in an included JSP page:

java.util.Hashtable id = ( java.util.Hashtable ) session.getAttribute("ids");
int customerID = Integer.parseInt( ( String ) id.get("custID") );

- And in the JSP which include the first page I just call this bean with:

user.OrderData obj_order = obj_order = new user.OrderData( conn );
user.dataObject.User obj_user = obj_order.getCustomerInformation( customerID );

Do you see any synchronization problems in the way I get the customer information? One of the users has reported that he recieved another customer name, than his name?
I agree. Here's the link:
subject: JSP synchronization
It's not a secret anymore!