java代码
@Controller @RequestMapping("/plan/") public class PlanController { //private ProjectTypeService projectTypeService; // @Resource // private WorkProgram workProgram; //进入工作计划表主页面 @RequestMapping("listUI") public String listUI() { System.out.println("进入plan.listUI"); return "table2"; } //处理点击提交之后的请求 @ResponseBody @RequestMapping("disposeSubmit") public JsonResult dispose(WorkProgram params) { WorkProgram w = new WorkProgram(); PhasePlan p = w.phasePlan(); System.out.println(params); System.out.println("进入/plan/disposeSubmit"); String phasePlan = params.getPhasePlan(); String[] phasePlans = phasePlan.split("##"); for(int i=0;i<phasePlans.length;i++) { String str[] = phasePlans[i].split("&&"); p.setSequence(i+1); p.setProgramContent(str[1]); p.setFinishTime(str[2]); p.setMember(str[3]); System.out.println("p="+p); } return new JsonResult("请求完成"); } }
javascript代码
function doPlan(){ var url = "plan/disposeSubmit.oo"; var params=getEditFormData(); if(params == "exception") return; console.log("JSON为: "+JSON.stringify(params)); $.post(url,params,function(result){ console.log("回调函数执行了"); console.log(result); //console.log("params="+params); //console.log(result); alert(result); }) }
返回类型JsonResult代码
public class JsonResult implements Serializable{ /** * */ private static final long serialVersionUID = -1780875855049989475L; public static final int SUCCESS=1; public static final int ERROR=0; /**状态:(SUCCESS,ERROR)*/ private int state; /**状态信息*/ private String message; /**具体数据*/ private Object data; public JsonResult(){ state=SUCCESS; } public JsonResult(String message){ this(); this.message=message; } public JsonResult(Object data){ this(); this.data=data; } public JsonResult(Throwable exp){ state=ERROR; this.message=exp.getMessage(); } public int getState() { return state; } public String getMessage() { return message; } public Object getData() { return data; } }
spring-xml文件
启动tomcat报错信息
删除spring-xml文件的这个内容后
tomcat启动不会报错,但是点击网页上按钮提交后提示状态码406
@RequestMapping("disposeSubmit")
@ResponseBody
这样试一下
你的拦截后缀是.oo?
ajax请求的时候,指定为application/json试试
以解决,加入json三个配置文件,并在spring.xml内加入配置