0
我希望得到一些我必須實現的幫助。非常感謝你提前。struts2 + jquery + ajax調用:從動作返回xml文件
我在做一個web應用程序與struts2。現在我需要實現一種方式,用戶可以通過獲得一個xml文件,但不需要重新加載網頁。
從JSP,與jquery,我已經實現調用Ajax(一個動作)這樣的:
$(function() {
[...]
$("#getXML").click(function() {
[...]
$.ajax({
type : "POST",
url : "Servlets.action",
data : "id="+$id+"&objects="+$objectsMap+"&relations="+$linesMap+"&inputs="+$inputs+"&option=2",
dataType : "xml",
success : function(data) {
//¿??
}
});
}); });
我已經定義在struts.xml中構造的動作的Servlet。
而且行動現在看起來是這樣的:
public class Servlets extends ActionSupport implements SessionAware, ServletRequestAware{
private ApplicationDao applicationDao;
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
public String execute() throws Exception {
[...]
if (request.getParameter("option").equals("1")) {
[...]
}
if (request.getParameter("option").equals("2")) {
[...]
File xml = new File(id+".xml");
XMLcreator.createXML(id,project,xml);
//I want to return the File object "xml" to the user through the jquery
}
else {
return ERROR;
}
return SUCCESS;
} }
我希望有人告訴我我怎麼能返回File對象「XML」到已下令它的用戶。
非常感謝你,
Aleix