Results 1 to 19 of 19
Thread: Applet making cookies
- 08-30-2010, 10:33 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 57
- Rep Power
- 0
Applet making cookies
Hello.
I have made an applet like test which has questions on which user answers and they got recorded to the database one by one when he click submit button.
I would like to make cookies to control user (to remember his action if he, for example uses refresh page) and not to allow him to does questions again (which he already did) and to write to database again.
I would also like to check his previous access to test (that is the applet) and not to allow him to run applet if he has already run it before.
Can anybody help me how to make cookies from my applet that can do all this?
I would be very grateful.
- 08-30-2010, 11:31 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Do you want to restrict the user to take past actions again, is it?
- 08-30-2010, 11:49 AM #3
Member
- Join Date
- Apr 2010
- Posts
- 57
- Rep Power
- 0
Yes, it is.
- 08-30-2010, 11:56 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I'm not sure what exactly your design do. But I'm not recommend you to use cookies, due to many reasons. Major threat is with the security, and also it's not possible to send more data. And also in some browsers, users may disable it, and so on.
You can disable the navigation bar in the browser. Or you can flag the last user activity and based on that redirect to the next state. Is that make sense to you?
- 08-30-2010, 12:03 PM #5
Member
- Join Date
- Apr 2010
- Posts
- 57
- Rep Power
- 0
When it starts, my applet has one question. User answers in text field and presses submit button. Then he clicks next button and he then goes to the next question. Next button works having counter in it that controls which question will be shown. I coded it like this:
If (counter==1){//write question one} else if.....
I hope I have succeed to explain my point.
This sounds like what I need. How can I do that?
And thank you
- 08-30-2010, 12:16 PM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Seems you've a questioner with you. Is that contain fixed number of question in each time?
- 08-30-2010, 12:25 PM #7
Member
- Join Date
- Apr 2010
- Posts
- 57
- Rep Power
- 0
Yes, 4 questions.
- 08-30-2010, 12:45 PM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Then It's simple actually.
In a table you can keep five columns actually. In each login create a session for a user, randomly generated number is much better. Then each question submit update the relevant column of the table. At the same time you've to check previous question has been answered or not. If yes simply you can forward it to the next question.
- 08-30-2010, 12:46 PM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Sine it's web based application, why don't you disable the navigation bar?
- 08-30-2010, 01:38 PM #10
Member
- Join Date
- Apr 2010
- Posts
- 57
- Rep Power
- 0
Ok, can you explain me that part about creating a session and about randomly generated number? I have never did that before.
I do make update of database record like you said and that is how I record those 4 answers in one row of table (one record). I suppose it means that is good, but I need help about that checking if the previous question has been answered or not.
Thank you for interesting in my problem.
- 08-30-2010, 01:49 PM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
About the session. Just forget about the word for a min. Once a user take your question how did you find who is he/she. You need kind of an identification. You cannot use names it's not practical, since it's not unique. So you need kind of an ID a unique one. Sessions are used for that, simply a lengthy string of letters and numeric. Simplest option you've is generate a random number of 15~20 numbers. Then there is very small probability to duplicate the same.
- 08-30-2010, 01:50 PM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
About tracking the previous questions, think about a simple logic. Only if a user answer the question only update the relevant column. If not the relevant field should be a null.
- 08-30-2010, 02:02 PM #13
Member
- Join Date
- Apr 2010
- Posts
- 57
- Rep Power
- 0
About session: I understand problem with full name, well, I thought putting simple auto increment id in database... Can you give me a simple example about that random number generating and demonstrate use of that? I know that I ask much, but it will be very helpful for me to see how it works.
About tracking the previous questions: do you mean that I should put that logic in database? I hope I have understood well.
- 08-30-2010, 02:09 PM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You've to do something like this.
About the track of question numbers, yes you can build the logic either in DB or withing your code. DB seems more effective since it's not a bulky process.Java Code:Random randomGenerator = new Random(); int iNum = randomGenerator.nextInt(10000);
- 08-30-2010, 02:29 PM #15
Member
- Join Date
- Apr 2010
- Posts
- 57
- Rep Power
- 0
How can I implement this random numbers logic in having session for one specific user and I am confused about how can I check according to this generator if he has been earlier on specific applet?
- 08-30-2010, 02:59 PM #16
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Once user login simply pass the number, may be as a URL parameter and so on. What you mean by specific applet?
- 08-30-2010, 03:34 PM #17
Member
- Join Date
- Apr 2010
- Posts
- 57
- Rep Power
- 0
I need logic to "know" how many times did he accessed applet and if he left it undone last time, when he runs applet again, he should go to that question on which he left last time. All that is to limit bad recording to database. And also, he can not do refresh page and run applet again from the beginning.
Where should I pass that random generated number? To database?
- 08-31-2010, 04:30 AM #18
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I'm not sure that you have an idea what's really want to do. Just think if you want to track how many times a user login to your application, there MUST be unique way to identify it. You cannot use the name. So what you should do? Each time you have to get an ID from the users, must be a unique.
Do you really what's mean by a random number? Each time it's changed. I advice you to use it only for an instance as a replacement for the sessions. Because it your case it's really no need to use real sessions.
What you have to do is, in each login you've to use an ID, a unique one. If users have to login to your application user name and the password, then in your record table there must be an ID as well.
- 08-31-2010, 04:32 AM #19
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I told you that until user answer a specific question leave the relevant cell as a null value. So using that you can simply track the next question that user has to take on after login again. Simply change the design of your record table to count number of participation from a single user, add another column and increment it value in each login.
Similar Threads
-
Code to make an Applet that downloads?
By Leeky in forum Java AppletsReplies: 0Last Post: 09-05-2009, 10:56 PM -
CooKies and Session
By makpandian in forum JavaServer Pages (JSP) and JSTLReplies: 3Last Post: 04-27-2009, 01:47 PM -
Make java applet a button
By hervey in forum New To JavaReplies: 31Last Post: 10-30-2008, 05:44 AM -
cookies
By lukky in forum JavaServer Pages (JSP) and JSTLReplies: 3Last Post: 09-02-2008, 07:46 PM -
JSP cookies example
By Java Tip in forum Java TipReplies: 0Last Post: 01-15-2008, 03:11 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks