jsp页面:
var clientTel = $("#clientTel").val(); var activityId = $("#activityId").val(); $.ajax({ type : "post",//发送方式 url : "/arweb/reserve/saveCode.action",// 路径 data : "clientTel=" clientTel "&activityId=" activityId , success: function(text){$("#randomCode").val(text);}, error: function(text) {alert("对不起,用户ID不存在,请输入正确的用户ID");} });
action类:
HttpServletResponse res = ServletActionContext.getResponse(); res.reset(); res.setContentType("text/html;charset=utf-8"); PrintWriter pw = res.getWriter(); pw.print(random); pw.flush(); pw.close();
pw.print(random);这里的random就是action要向jsp传的值,在jsp中,success: function(text)这里的text就是接收从action传过来的值。