This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Struts and the fly likes Everytime i am refreshing(F5) a page the action gets called(How can i avoid?) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Everytime i am refreshing(F5) a page the action gets called(How can i avoid?)" Watch "Everytime i am refreshing(F5) a page the action gets called(How can i avoid?)" New topic
Author

Everytime i am refreshing(F5) a page the action gets called(How can i avoid?)

Manoj Amrutkar
Ranch Hand

Joined: Apr 15, 2006
Posts: 47
I have one chat application, When user logs in he has the URL as
http://localhost:7001/sample/message.do
There is a text area(TA), text field(TF) and a button(Send). Now user enters text in TF and clicks on Send the text concats with existing text in TA. In the corrosponding action the Context String messageList variable get updated in the background.
Now the big problem:It's fine once time but if i refresh a page say by pressing F5. same action gets called and without any reason the empty string gets concatenated(with new line character) to the list which is not what i want. Basically it should not even if it is empty.
Partial Solution:I have one session varible say newUser set to "true". I will "false" it in action but again i have to make it true on click of Send just before the message.do or corrosponding action gets called. Can i do it in javascript, what will be the code for it?
Is there any other way to have difference in refresh and Send button click?
Can i have something in between Send click and Action class execution to access session variable?

Please have your expert advice....

Thanks in advance
Manoj Amrtkar
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
i think you need a more fine-grain session concept. if you had an action like "displayChatPage" which you use to render the page, and another action "processUserInput" which gets submitted by the form, your problem would be solved :-)

best regards,
jan

sorry, i just see that "session" is wrong and extremely misleading. i meant "action"
[ September 07, 2006: Message edited by: Jan Groth ]
Manoj Amrutkar
Ranch Hand

Joined: Apr 15, 2006
Posts: 47
Sorry but the reply is not elaborative enough. Can you just tell me how can i call those two actions seperately. I mean one will be for Send button's click but what about other to refresh a page? It's really confusing?

Thanks
Manoj Amrutkar
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
hey, untwist you brain a bit :-)

forget about your design-structure for the next minute, and try to follow this concept-proposual for a chat app with login:

(1) a user hits your url and gets a welcome-screen with login
-> rendered by loginShow.do

(2) on this screen we have a login form
-> submitting to loginProcess.do

(3) the login is processed, and if successfull, the user sees the chat-screen
-> processed by loginProcess.do
---> failure redirects to errorPageShow.do
---> success redirects to chatShow.do

(4) the user sees the chat screen. on this screen we have a form which processes the possible user input
-> screen is rendered by chatShow.do (as said in (3))
-> form submits to userInputProcess.do (we se in a sec)

(4.1) the user hits f5
-> chatShow.do renders the screen again

(4.2) the user submits a form
-> userInputProcess.do processes the user input and possible redirect back to chatShow.do

:-)

4.1 and 4.2 are the import parts which make your question obsolete. the point is that you render your screen with a different action then you process the input.


okay?

hope it helped a bit,
jan

got it?

feel free to post
Manoj Amrutkar
Ranch Hand

Joined: Apr 15, 2006
Posts: 47
Yup,
Thanks a lot for your reply and very important time.
It was really so very usefull.
Thanks once again

Manoj Amrutkar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Everytime i am refreshing(F5) a page the action gets called(How can i avoid?)
 
Similar Threads
Refreshing a page calls previous action
Can i avoid execution of action on page refresh(F5)..
how to differ between new request and page refresh..
Jsp Refresh problem
How to identify when refresh button of browser or f5 is pressed