aspose file tools*
The moose likes JSP and the fly likes What to do to make this  web page thread safe? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "What to do to make this  web page thread safe?" Watch "What to do to make this  web page thread safe?" New topic
Author

What to do to make this web page thread safe?

Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Hi Folks,

I'm trying to write a jsp that invloves the insertion , updation etc of a set of records. Right now , I'm just trying to insert a set of records after selecting values from the dropdown and then inserting them.The thing is that I'm able to get the page to work perfectly when I use it with a single user , however when multiple users try to insert simultaneously , the values of each other.
Below, are my code snippets.

The usage of scriptlets at that point was unavoidable ,due to a few external circumstances. I understand that their usage is not encouraged.And below is how I process my request in the servlet
Servlet.

I just dont seem to understand why the values are being overwritten . Any pointers would be helpful.

And Sorry for the long post!! .I really cant figure out where I 'm going wrong and hence the lengthy post!


Learning and Learning!-- Java all the way!
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1


JSP's are not thread safe by default. To make them thread safe they have to implement SingleThreadModel.

Add isThreadSafe attribute to your JSPs as below.



Cheers,
Raj.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Now THAT was really bad advice, ignore it.

JSP can be Thread safe with respect to multiple requests by careful design.

If multiple users are seeing each other's values, it suggests your servlets or jsp are using instance variables instead of good practice.

Bill
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

Raj Kamal wrote:
JSP's are not thread safe by default. To make them thread safe they have to implement SingleThreadModel.

Wow! Really bad Advice! Do not do this! Ever.

It is unlikely that the JSP is a source of the problems. More likely (as William pointed out) improper variable use is the likely culprit.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

And, scriptlets are always avoidable with proper structure and planning.

The use of the <%! %> style of scriptlet (which does not appear to be being used here) is also a likely culprit for introducing threading issues.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

And one more piece of advice: using uppercase in HTML makes it really hard to read and sort of went out of vogue in 1998. I'd suggest using lowercase for HTML as if you were using XHTML (even if you aren't). It looks more modern and is more readable.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

You didn't say what data was being misdirected. There could be all kinds of things happening. For example somebody might have used static variables in the Consumer class. Or any number of other things. So knowing what data was the problem is an important clue for you.
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Sorry for all the noise folks!Bad ,bad instance variables !
Thanks for the advice !
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1

Sorry folks...

For the suggestion (if it was a bad one and there seems to be a large number of experts agreeing it was a BAD one).

I thought this was the way to make JSPs Threadsafe. Below are a few sites I found when I ran a quick google:

Webpage #1
Webpage #2
Webpage #3
Webpage #4
Webpage #5

I do not wish to argue but it was the way I was doing things till now as well...

Well one more to 'un-learn'.



Cheers,
Raj.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What to do to make this web page thread safe?