1
我正在使用Java和Play框架的MVC項目,我遇到了一個問題。這裏是代碼的有趣的部分(我把它清理了一下):獲取一個錯誤500,但返回正常()
控制器:
public Result acceptInputSimulationPension() {
if (request().getHeader(CONTENT_TYPE) == null) {
return badRequest("error: no content type");
}
if (!request().getHeader(CONTENT_TYPE).contains("multipart/form-data")) {
return badRequest("Error: wrong content type. Expected multipart/form-data, got " + CONTENT_TYPE);
}
Form<String> form = Form.form(String.class).bindFromRequest();
Pension project = new Pension();
project.setMaxloss(form.field("maxloss").value());
// setting some other parameters...
project.setIdUser(Application.user.getId());
if (project.getMaxloss() == 0) {
return badRequest("error: maxloss datalist malformed");
}
double[] flows = Application.getPensionFlows(project, (int) project.computeContributionYears(), (int) project.computeAdditionalIncomeNeeded());
Savings savings = new Savings((int) project.getInitialContribution(), flows, (int) project.computeContributionYears() * 12);
Ebean.save(project);
session("init/pension/maxloss"+project.getId(), form.field("maxloss").value());
// setting some other session variables...
ObjectNode result = Application.jsonEncoder.encodeFinalSimulPension(project, savings.getSavings(), flows, false, true);
result.put("id", project.getId());
System.out.println("hello?");
return ok("test");
}
我返回OK(「測試」),以確保該問題並非來自結果變量。
而AJAX:
function ajaxPOST_simulation(data, id, formName) {
$.ajax({
type: 'POST',
url: "/input/simulation/"+formName,
processData: false,
contentType: false,
data: data,
success: function (resp) {
alert("ok");
},
error: function (resp) {
alert("error: " + resp.responseText);
}
});
}
中的System.out.println(「你好」)成功顯示我的終端上,所以我想我行返回(「測試」),但我得到這個錯誤作爲提醒:
error:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Execution exception</title>
<link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSU... etc.
這怎麼可能? 提前謝謝!
編輯: 我剛纔發現HTML代碼對應NullPointerException,但我仍然不知道這裏可能是NULL。即使結果變量不是NULL,看起來確定...