第一步:前台的Js Demo:
function submitForm(){
var hostname = $("#hostname").val();
var port= $("#port").val();
var validName= $("#validName").val();
var vp= $("#vp").val();
$.getJSON("req?hostname="+hostname+"&port="+port+"&validName="+validName+"&vp="+vp, function(json){
var iss = json.issuccess //前端解析
if(iss=="S") {
$("#etable").append("<tr><td>"+hostname+"</td><td>"+port+"</td><td>"+validName+"</td><td>"+vp+"</td><td>"+json.validcode+"</td></tr>");
}
});
}
第二步:后端Demo:
@RequestMapping("/main/req")
public String save(){
Date date = new Date();
String hostname = this.request.getParameter("hostname");
String port = this.request.getParameter("port");
String validName = this.request.getParameter("validName");
String vp = this.request.getParameter("vp");
String validcode ="";
validcode = DateFormatUtil.StringFromDate(date);
validcode = Base64.encode(validcode.getBytes());
String savetime = DateFormatUtil.StringFromStanderDate(date);
String id = GUID.getGUID();
Mailconfig mailconfig = new Mailconfig();
mailconfig.setId(id);
mailconfig.setHostname(hostname);
mailconfig.setPort(port);
mailconfig.setSavetime(savetime);
mailconfig.setValidCode(validcode);
mailconfig.setValidName(validName);
mailconfig.setVp(vp);
boolean res = mailService.save(mailconfig);
Map<String,Object> returnMsg = new HashMap<String,Object>();
try {
if(res == true){
returnMsg.put("issuccess", "S");
returnMsg.put("validcode", validcode);
this.response.getWriter().print(JSONObject.fromObject(returnMsg));
}else {
returnMsg.put("issuccess", "E");
this.response.getWriter().print(JSONObject.fromObject(returnMsg));
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
原文地址:http://blog.csdn.net/java_zhong1990/article/details/46417355