aspose file tools*
The moose likes Struts and the fly likes action called two times Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "action called two times" Watch "action called two times" New topic
Author

action called two times

dev pandya
Greenhorn

Joined: Jun 10, 2008
Posts: 14
i have found one problem in last 2 or 3 days that some strut action is called two times from the jsp page and my entire web application perform the different operation and fire the exception in action class.if possible please give me solution.
"loadcurrentbooking" mehtod is called from the DispatchAction class and load the jsp page but "loadcurrentbookingmethod" is called the two times.

if possbile please give me solution as fast as possible.
Sachin Adat
Ranch Hand

Joined: Sep 03, 2007
Posts: 213
Can you give details........

If you are calling a javascript function on the click of a submit button(html:submit) and then doing a form submit in your javascript function, it can execute the action class method two times.

Try changing the submit button to a normal button(html:button)

Hope this helps you.........


SCJP 6
How To Ask Questions On Java Ranch - How To Answer Questions On Java Ranch
dev pandya
Greenhorn

Joined: Jun 10, 2008
Posts: 14
thanks sachin for reply
but i have use the button image like name is load.png and when user click on this button the java sctipt is called and java sctipt is inturn called the DispatchAction's class method.
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

Hi Dev,
There's a little care you need to consider when you use a submit as a image because image buttons when clicked get submited in form of co-ordinates (X=??&Y=??) which creates bit problem with the Dispatch Action Handler to identify the url pattern and recognise the required parameter that was configured as method parameter in struts-config file to diapstch to a specific method.Its often not entertained to use DispatchAction & LookUpDispatchAction with image buutons. But there's way to perform in a javascript.Just add a hidden property , assign a method-name as value to it. On click of the image calls Js function or submits to the disptcher.
Hit me back if am wrong


Thanks & Regards
Sidharth Pallai
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

Hi Dev,
Your problem may be the cause of submission through both JS function and general form submission.Try submit either of two.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Hi,
from my point of view...
DispatchAction=group related Action,,,,so try to concentrate on calling methods from jsp....coollll
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

Originally posted by seetharaman venkatasamy:
Hi,
from my point of view...
DispatchAction=group related Action,,,,so try to concentrate on calling methods from jsp....coollll


Is it a good way to access directly the Actions from JSP(View).Is it what you want to say or your response refers a different way to the problem concerned.
dev pandya
Greenhorn

Joined: Jun 10, 2008
Posts: 14
hi Sidharth Pallai thanks for reply

but i have found same problem again,i remove the image button and put the simple html:button but same problem is arise.

Problem is like when
when i load the booking.jsp page that is load using the loadcurrentbooking method of DispatchAction class.
When i press the add button(without image) at a time record is insert into the database and message.jsp page is display.And success msg is display.when i click the
back button of message page(using the form submit) at a time loadcurrentbooking method is called again but two times.
Java script of booking.jsp no submit() method is available.then also
loadcurrentbooking method is called two time.

if possible please give me a find solution.
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

Hi Dev,
What is the logic you have used while clicking the back buuton?
Am not getting the actual cause of it.But what i think is that on click of back button it should call the action and display them in booking.jsp.Isn't it? Try out to call the action from a javascript function which should be invoked upon click of back button.Declare such JS function in message.jsp.Am not sure why the back triggers double invocations upon form submission.Well it shouldn't happen unless it tailored to do so.
dev pandya
Greenhorn

Joined: Jun 10, 2008
Posts: 14
hi Sidharath
in booking.jsp page we put the alert box which is alert message one time but system.out.println in jsp page and loadcurrentbooking method of dispatchaction class is called two times.

Regards
Devarshi Pandya
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

Hi Dev,
Please make me your flow understand very clearly, am not getting the way you reply.If there was a message.jsp to display successfull insertion then where does the alert came in between? Where exactly the back button exist i mean in which JSP Page?
Irrespective of its location try to associate a JS function with the back button, which will invoke the appropriate action upon click.You need to manually invoke with the action path URL inside the JS fucntion.
The JD Function would be like this..

And the back button onclick attribute like--
<input type="submit" name="back button" on_click="actionInvoker()"/>
dev pandya
Greenhorn

Joined: Jun 10, 2008
Posts: 14
hi Sidharth
ok i explain again actually problem

first of all booking.jsp page is display using the loadcurrentbooking method of TicketBookingAction class.Every thing is done fine.And i put the one temperaray message box in the java script of booking.jsp page which is highlighted when the booking.jsp page is loaded.

After the click on add button of the booking.jsp page at a time add method of TicketBookingAction class is called and the data inserted into the database.After that message page is displayed using the message.jsp page.One back button available in the message.jsp,when i click on the back button of the message.jsp page at a time loadcurrentbooking method of TicketBookingAction class is called two time but mesage box is highlighted one time(Available in the booking.jsp page which is highlighted when booking.jsp page is loaded) and System.out.println in the booking.jsp page is display two time.

Regards
Devarshi
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

Hi,

Didn't my last post helped you? Its OK, I understood your flow.
The input page of your action is booking.jsp and success page is message.jsp.In between the action process the request of loading the bookings.It seems there's a problem with the code that get executed once you click back in message.jsp. Try to find out how the action get called when back is clicked
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

Hi,

Didn't my last post helped you? Its OK, I understood your flow.
The input page of your action is booking.jsp and success page is message.jsp.
In between the action process the request of loading the bookings.It seems there's a problem with the code that get executed once you click back button in message.jsp.
Try to find out how the action get called when back button is clicked.Get me the code you use to fire the loading action in message.jsp.
dev pandya
Greenhorn

Joined: Jun 10, 2008
Posts: 14
hi Sidharth
Tanks for help me.
i have find the problem,Actually problem is arise when using the CSS file.
I remove the CSS from entire Booking.jsp page and problem is solved.


Regards
Devarshi Pandya
Akbar Khan
Greenhorn

Joined: Jun 13, 2007
Posts: 24
Problem is with browsers.

You will see there will be no two calls when using MOZILLA browser instead of IE.

change submit button to simple button but not as html:button but as input type html .....
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

Thank you Dev & Akbar

I have never thought that there could be browser incompatibility with form input.
rajesh subram
Greenhorn

Joined: Jul 15, 2008
Posts: 1
Originally posted by dev pandya:
i have found one problem in last 2 or 3 days that some strut action is called two times from the jsp page and my entire web application perform the different operation and fire the exception in action class.if possible please give me solution.
"loadcurrentbooking" mehtod is called from the DispatchAction class and load the jsp page but "loadcurrentbookingmethod" is called the two times.

if possbile please give me solution as fast as possible.



I HAD the same problem, and the culprit was <!--<html:img onsubmit="this.form.submit()">--> tag it was doing double submission.

When i used a simple <!--<img src="" on click="document.applForm.submit()"/>--> it was fine.

I spent 8hrs wondering why the execute method was running twice. It loads the Actionform , then goes to Action -> mapping.findforward -> requestProcessor -> ActionServlet --->surprise goes to back to Action.execute
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: action called two times