• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

ID numbers sometimes confused in JSP

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I developed a forum (BBS) by myself. The basic thing is to enable the users to post new topic and follow topics. Also the user need to be able to view the topic list and the detailed content of each topic. When they are posting a topic (new or follow), they can also upload a attachment.

To implement these functions, I have several files (which may have problem), they are: topics.jsp, details.jsp, newTopic.jsp, followTopic.jsp, upload.jsp. Also, I use forumID, topicID, and postID to uniquely identify a post (like every forum)

All these functions work perfectly in normal situations. But occasionally, when there are about 20 active people (registered users) on my website (about more than 100 visitors at that moment), serval of them are trying to post. The following problem may come (not always):

1. When they are trying to view the post details (called details.jsp file), they get the content of another post. You can see from URL address in IE, the forumID, topicID are correct, but the details are from another seems random one. And normally, in one page, I set it to show 10 posts of one topic. But if such thing happened, it can only show one post sometimes. And sometimes, the first several posts are correct, but the last several post are from other topic with different forumID and topicIDs. But if you refresh the page, most probably, you will get the correct content.

2. When people try to reply (follow) a topic, the post is appended to another topic, which means the same. The forumID and the topicID was confused the system.

3. When people were trying to upload a file, I firstly put the file in a temporary directory under somedirectory/userID/ and then move it to the destination. But sometimes, the attachment cannot be found when the system was trying to move it because the file had been put to a directory like:

somedirectory/anotheruserID.

And I know that the user of userID and the user of anotheruserID were both active at that moment.

I am coding all these function in JSP and mysql, using Apache and tomcat.

All the 3 problems all look similar, which may be due to the synchronization problem or, anyway, because the system confused of processing the request from diffrent users.

Anybody please kindly give me some idea? Thanks very very much!
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like the classic symptoms of a thread-safety issue.

Are you storing any data in instance variables of a servlet? Are you using the <!% %> construct in JSPs to store variables?


P.S. Could you do us a favor and modify your display name to mixed case rather than uppercase. It'll be easier on all our eyes. Thanks.
 
Philip Shou
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, on top of these files, I have something like:

<%!
...

int forumid, subjectid, postid;

...
%>

so what's the problem of using this way?

I am new here. I don't know how to modify my display name. Thanks for your reply and I am sorry about my display name.
 
Philip Shou
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But in the upload.jsp file, I am using this code:

int userid = umUtil.getUserIDByName(username, host, dbname, user, pass);

and the userid is sometimes messed up as well.

By the way, the umUtil is more like a static class, although it is not. In the class of umUtil, the method of getUserIDByName is just a connection to the database and then select the ID, and then close the connection and return the userid.

And I define this bean on the top of this file like this:

<jsp:useBean id="umUtil" class="um.UMUtil" scope="session" />

Thanks very much!
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Philip SHOU:
Yes, on top of these files, I have something like:

<%!
...

int forumid, subjectid, postid;

...
%>

so what's the problem of using this way?

I am new here. I don't know how to modify my display name. Thanks for your reply and I am sorry about my display name.




Variables declared in the outside of your service method (For JSPs, that means within the <%! ...%> blocks) are common to all requests. The simplest way to fix this is to move the declarations out of that block.
 
Philip Shou
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much!

But for this:

int userid = umUtil.getUserIDByName(username, host, dbname, user, pass);

Why it happens the same problem?

Are there any where else I should fix?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic