JavaScript代码
$.ajax({ type:"post",//相对于form的method url:"ajaxAction.action",//传送到的Action或URL地址 async:true,// data: {"time":time},//如果要传递多个参数{”param1”:param1,”param2”:param2,”param3”:param3} dataType:"text",// success:function(data) {//获取返回值 document.getElementById("content").value=data; //你需要进行的业务逻辑操作 },error:function(e) { alert("验证失败!"); } });
Struts.xml配置文件
<actionname="ajaxAction" class="myAction" method="ajaxAction"></action><!—-不设置返回值 -->
Action.java方法
private ServletRequestrequest=ServletActionContext.getRequest(); private HttpServletResponseresponse = ServletActionContext.getResponse(); publicvoid ajaxTheNOCheck()throws Exception{ try{ String Message="返回字符串"; response.setCharacterEncoding("utf-8");//设置编码格式 PrintWriter writer =response.getWriter(); writer.write(Message); //写入Message,返回值为Message里的值 writer.close(); }catch (Exception e) { e.printstacktrace(); log.error("程序异常:",e); throw new Exception(e); } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。