Action is called twice in single request in grails

Posted By : Shiv Kumar | 18-Apr-2014
Sometime it happens that controller's action/method is called twice back to back.At first time it is called with the right parameter you have passed in request but at second time it is either called with no parameter or with undefined parameters.I have faced this problem many times but atlast find out the hack for this.
 
Root Cause :
1. The main cause of problem is that if rendered view[other than default(i.e testAction.gsp)] from action lets it is "TestAction" contains some empty source fields then action is called by browser again to fetch the file from src field url path.
 
2. Same problem can also be occurred due to href="" and href="#" in rendered view.
 
Let testAction.gsp contains :
<img src="" alt="User Image" width="500" height="500">   // Causes twice call to rendering action. 
 

Solution:

Never leave such empty src in rendered view.Always fill some suitable text in it except empty string and "#".
 
 
Thanks 
Shiv Kuamr

 

About Author

Author Image
Shiv Kumar

Shiv is an experienced Java Developer with a strong background in multiple technologies. He specializes in defining system architectures to ensure reliable and resilient solutions. He possesses a comprehensive understanding of the latest technologies and has hands-on experience in Core Java, Spring Boot, Hibernate, Apache Kafka messaging queue, Redis, as well as relational databases like MySQL and PostgreSQL, and non-relational databases like MongoDB. He excels in API implementations, Microservices, Web Services development, testing, and deployments. Shiv actively contributes to code enhancements and consistently delivers valuable contributions to various client projects, including Fabtrack, Pando, Pandojo, Digikam, WhatsApp Integration, Croniz, Punchin Application, Script TV, Bhaasha, and more. He demonstrates strong analytical skills and a creative mindset. In addition, he has a passion for reading books and exploring new technologies and innovations.

Request for Proposal

Name is required

Comment is required

Sending message..