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