【发布时间】:2016-11-29 06:15:21
【问题描述】:
我在通过 ajax 调用设置动作类字符串时遇到问题。这是我的代码
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 设为 null。我已尽力解决它,但找不到丢失的东西。非常感谢。
【问题讨论】:
-
你在哪里定义了你的 ActionForm 我猜你将 testString 作为 Post 正文提交?但我看不到您的 Actionform 定义,其中操作将填充此值