我使用Struts 2和Ajax。我無法在Action類中獲取參數。我有一個表格是這樣的:Struts 2獲取Action類中的參數
<s:form id="form" onSubmit="sendAjaxRequest();">
<s:textfield name="libelle" label="Libelle" />
<s:textfield name="id" label="id" />
<s:submit value="Valider" />
<s:reset value="Effacer" />
</s:form>
當我審視這是在HTTP閱讀器發送的請求:
Content-length contains libelle=Test&id=13
我的要求很不錯!
在我的動作類:
public class MyAction extends ActionSupport {
private String libelle;
private Integer id;
public String getLibelle() {
return auteur;
}
public void setLibelle(String libelle) {
this.libelle = libelle;
}
public String getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String execute() {
System.out.println("Libelle " + libelle);
System.out.println("Libelle " + this.libelle);
}
}
在我的行動libelle這。 libelle爲null。我不知道我是否犯錯。如果有人可以給我幫助。謝謝。
我發現我的問題,但沒有解決方案。我檢查生成的html代碼,我看到以下內容:
<form id="form" name="form" action="/path/MyOtherAction.action" method="post" onSubmit="sendAjaxRequest();">
<table class="wwFormTable">
<tr>
<td class="tdLabel"><label for="form_libelle" class="label">Libelle:</label></td>
<td><input type="text" name="libelle" value="" id="form_libelle"/></td>
</tr>
<tr>
<td class="tdLabel"><label for="form_id" class="label">id:</label></td>
<td><input type="text" name="ide" value="" id="form_id"/></td>
</tr>
...
<td colspan="2"><div align="right"><input type="submit" id="form_0" value="Valider"/>
..
<td colspan="2"><div align="right"><input type="reset" value="Effacer"/>
..
</table>
</form>
所以MyOtherAction首先在我的sendAjaxRequest之前執行。如何在我的表單中刪除動作MyOtherAction? 感謝您的閱讀。
你需要提供一個有效的動作,這個動作不會被編譯,因爲這個類沒有定義導師......所以考慮到你有一個運行時錯誤,很難說出發生了什麼。 – Quaternion
四元數我正確,這是一個錯誤。 – Pracede
請創建一個工作示例,然後剪切並粘貼它,我可以直觀地看出這也會失敗。 – Quaternion