저는 struts2에 익숙하지 않습니다 만, 메소드 호출에서 이름에 의해 execute() 메소드가 디폴트로 호출된다는 것을 알고 있습니다. 그러나 같은 액션 클래스에서 정의 된 다른 메소드를 호출하는 방법은 무엇입니까?struts2의 한 동작에서 정의 된 다른 메서드를 호출하는 방법은 무엇입니까?
아래 예제에서 @Action 주석 덕분에 ajax에 URL 링크를 설정할 때 execute() 메서드가 호출됩니다. saveJSONDataAction.action
덕분입니다.
ajax를 통해 otherMethod()를 호출하는 URL은 어떻게 표시되어야합니까?
Action 클래스 :
@ParentPackage("json-default")
@Action(value="getJSONDataAction")
@Result(name="success", type="json")
public class JSONDataAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private List<Report> data = new ArrayList<Report>();
public JSONDataAction(){
data.add(new Report(1, "Chris", true, "2008-01-01", "orange"));
}
public String execute() {
return SUCCESS;
}
public String otherMethod() {
//do something else ..
return SUCCESS;
}
// getters and setters
}
Ajax 호출 :
$.ajax({
url: "../json/saveJSONDataAction.action",
data: data,
dataType: 'json',
contentType: 'application/json',
type: 'POST',
success: function (res) {
if (res.result === 'ok') {
$console.text('Data saved');
}
}
});
아약스에 의해 otherMethod() 메서드를 호출하는 방법?
감탄 부호가있는 문법이 있다고 생각합니다. '/ json/saveJSONDataAction! otherMethod.action'과 비슷합니다. –