0
我在通過ajax調用設置動作類String時遇到問題。這裏是我的代碼使用ajax設置Action類屬性jquery Struts-1
DashBoardGraphAction.java
public class DashBoardGraphAction extends DispatchAction
{
private String testString;
public ActionForward getTransactionsByStatus(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
System.out.println(fromDate);
return null;
}
public String getTestString() {
return testString;
}
public void setTestString(String testString) {
this.testString = testString;
}
Ajax調用如下:
<script>
var testString = "testName";
$.ajax({
url: '${pageContext.request.contextPath}/gettransactionData.do?parameter=getTransactionsByStatus',
type: 'POST',
data: 'testString='+testString,
dataType: 'json',
success: function(data)
{
str = data;
},
async:false,
error: function(XMLHttpRequest, textStatus, errorThrown){
alert('Error ' + textStatus);
alert(errorThrown);
alert(XMLHttpRequest.responseText);
}
});
</script>
struts-config.xml中
<action path="/gettransactionData" parameter="parameter"
type="com.pp.dashboard.DashBoardGraphAction">
<forward name = "getTransactionsByStatus" path = "/jsp/pp/dashboardReportStatus.jsp" />
<forward name = "getTransactionsByProcessor" path = "/jsp/pp/dashboardReportProcessorWise.jsp" />
</action>
當操作調用我得到的TestString爲空。我盡力解決它,但找不到缺失的東西。任何是非常感謝。
你在哪裏定義了你的ActionForm我猜你是在提交testString作爲Post主體?但我無法看到你的動作形式定義,其中動作將填充此值 – Bilal