我有一个下面给出的行动方法 -
public String getCommissionaryOfficeByCustomLocation() {
Connection conn = null;
try {
ApplicantDbMethods db = new ApplicantDbMethods();
conn = db.getConnection();
commissionaryOffice = db.getCommissionaryOffice(conn, selectedCustomLocation);
return SUCCESS;
} catch (Exception ex) {
return ERROR;
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException ex) {
Logger.getLogger(ApplicantRegistrationDetails.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
我在下拉列表的onChange
事件中通过Ajax调用此方法。当我在调试模式下运行应用程序时通过Ajax调用此操作后,我看到在执行操作方法后,再次调用此操作方法,然后自动调用另一个操作方法。另一种方法是 -
public String getContactPersonForFutureCommunications() {
Connection conn = null;
try {
session = ActionContext.getContext().getSession();
if (session == null) {
return ERROR;
}
String applicantId = session.get("ApplicantId").toString();
if (applicantId == null) {
return ERROR;
}
ApplicantDbMethods db = new ApplicantDbMethods();
conn = db.getConnection();
// db.insertFutureContactPerson(conn,applicantId,futureContact);
if ("Other".equals(futureContact)) {
return "OTHER";
}
return SUCCESS;
} catch (Exception ex) {
return ERROR;
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException ex) {
Logger.getLogger(ApplicantRegistrationDetails.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
两个动作方法都在同一个动作类中。
jQuery方法只调用一次onChange
事件.jQuery方法是 -
function getCommissionaryOffice(customLocation) {
var location = $('#' + customLocation).val();
$.ajax(
{
type: 'POST',
url: 'getCommissionaryOffice',
data: {selectedCustomLocation: location},
//async: false ,
success: function(data) {
var commissionaryOffice=data.commissionaryOffice;
$('#commissionaryOffice').val(commissionaryOffice);
},
error:function(data){
alert("error getting commissionay office!");
}
});
}
我不知道为什么会这样,请帮忙
struts.xml
中的条目如下所示 -
<package name="default" extends="json-default">
<result-types>
<result-type name="tiles"
class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<action name="getCommissionaryOffice" class="applicant.ApplicantRegistrationDetails" method="getCommissionaryOfficeByCustomLocation">
<result name="success" type="json"/>
</action>
<action name="FutureContactPerson" class="applicant.ApplicantRegistrationDetails" method="getContactPersonForFutureCommunications">
<result name="input" type="tiles">FutureContactDetails</result>
<result name="success" type="tiles">SuccessfullySubmitted</result>
</action>
</package>