Note that there are some explanatory texts on larger screens.

plurals
  1. POStruts2 AJAX form submission - Action is called twice
    primarykey
    data
    text
    <p>I'm trying to submit a form using ajax within struts2. Therefore I'm using a jQuery link to submit out of the form. With this link I call my action, which executes a SQL query to my database and inserts a new record with the data me or the user was filling in the form. Well, that's the plan and actually that's how it works. But for some reasons <strong>my action is called twice</strong> and I really don't know why..</p> <p>This is my JSP:</p> <pre><code>&lt;%@ taglib prefix="s" uri="/struts-tags" %&gt; &lt;%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%&gt; &lt;%@ taglib prefix="sj" uri="/struts-jquery-tags"%&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;s:form id="formId" name ="formId" theme="simple" method="post" action="" &gt; &lt;s:textfield id="txt1" name="txt1" /&gt; &lt;sj:spinner id="spr1" name="spr1" /&gt; &lt;/s:form&gt; &lt;s:url var="createtesturl" action="create-test"/&gt; &lt;sj:a id="linkId" dataType="json" href="%{createtesturl}" onSuccessTopics="handleJsonPeriodNew" formIds="formId" button="true" buttonIcon="ui-icon-gear" &gt;Submit&lt;/sj:a&gt; </code></pre> <p>This is my action (<strong>here the execute method is called twice</strong>):</p> <pre><code>@ParentPackage(value = "json-default") public class CreateTestAction extends ActionSupport { private static final long serialVersionUID = 2864711857038235887L; private static final Logger log = LoggerFactory.getLogger(CreateTestAction.class); private String txt1; private String spr1; private Boolean success = false; @Actions( { @Action(value = "/create-test", results = { @Result(name = "success", type = "json") }) }) public String execute() { DbCon dbCon = null; try { dbCon= new DbCon(); success = dbCon.createNewTest(txt1, spr1); } catch (Exception e) { log.error("Exception", e); } finally { if (dbCon!= null) { dbCon.close(); dbCon= null; } } return SUCCESS; } //Getters and Setters for Attributes public String getTxt1() { return txt1; } public void setTxt1(String txt1) { this.txt1= txt1; } public String getSpr1() { return spr1; } public void setSpr1(String spr1) { this.spr1= spr1; } public void setSuccess(Boolean success) { this.success = success; } public Boolean getSuccess() { return success; } } </code></pre> <p>May anyone can help me?!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload