Jquery ajva 页面请求 (留言板 提交)
<%@ page contentType="text/html; charset=utf-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> <script src="${application.WebResourceUrl }/scripts/global/lib/jquery/addons/jquery.validate-1.7/jquery.validate.js" type="text/javascript" language="javascript"></script> <script type="text/javascript" src="${application.WebResourceUrl }/scripts/global/lib/jquery/core/jquery-1.4.2.min.js"></script> <script type="text/javascript" > function validateForm(){ var check = true; if ($("#msgLinkman").val() == "") { $("#msgLinkman").parent().next().css('color', 'red'); check=false; }else{ $("#msgLinkman").parent().next().css('color', '#999999'); } if ($("#msgMobile").val() == "") { $("#msgMobile").parent().next().css('color', 'red'); check=false; }else{ $("#msgMobile").parent().next().css('color', '#999999'); } if ($("#msgContent").val() == "") { $("#msgContent").parent().next().css('color', 'red'); check=false; }else{ $("#msgContent").parent().next().css('color', '#999999'); } check = false; $("input[type=checkbox]").each(function(){ if($(this).attr("checked")==true || $(this).attr("checked")=='checked'){ $("#msgArea").parent().next().css('display','none'); check=true; return false; }else{ $("#msgArea").parent().next().css({'color':'red','display':'block'}); } }); if($("#msgArea").attr("type")=="text"){ if($("#msgArea").val() == ""){ $("#msgArea").parent().next().css({'color':'red','display':'block'}); check=false; }else{ $("#msgArea").parent().next().css('display','none'); } } return check; } $(function () { $("#ajax_save_msg").click(function () { if(validateForm()==false){ return false; } $.ajax ({ //请求登录处理页 url: "/business/msg/bsn_msg_save_ajax.action", //登录处理页 type: "post", //传送请求数据 data: $("#business_msg").serialize(), success: function (result) { //登录成功后返回的数据 if(result=="success"){ alert("提交成功!"); location.reload(); this } if(result=="error"){ alert("提交失败,请重新提交!"); } } }); }); }); </script> <form id="business_msg" name="business_msg" method="post" action="${application.localDomain}/ucenter/client/bsn_msg_save.action"> <input type="hidden" name="businessMsg.msgReceiveUid" value="${frontBusinessGyDetail.businessGy.usrId}" /> <input type="hidden" name="businessMsg.msgBusinessId" value="${frontBusinessGyDetail.businessGy.gyId}" /> <input type="hidden" name="businessMsg.msgBusinessType" value="gy" /> <dl class="woyaoliuyan"> <dt>我要留言</dt> <dd> <div class="layout_group"> <div class=""> <label><font color="#FF0000">*</font>联系人:</label> <p class="formbox"> <input class="ipt" id="msgLinkman" name="businessMsg.msgLinkman" type="text" onchange="validateForm();"/> </p> <p class="tips">请填写您的真实姓名</p> </div> <div class=""> <label><font color="#FF0000">*</font>联系电话:</label> <p class="formbox"> <input class="ipt" id="msgMobile" name="businessMsg.msgMobile" type="text" onchange="validateForm()"/> </p> <p class="tips">方便项目负责人与您联系</p> </div> <div class=""> <label>QQ:</label> <p class="formbox"> <input class="ipt" id="msgQq" name="businessMsg.msgQq" type="text" /> </p> <p class="tips">请输入您的qq号码</p> </div> <div class=""> <label>电子邮件:</label> <p class="formbox"> <input class="ipt" id="msgEmail" name="businessMsg.msgEmail" type="text" /> </p> <p class="tips">请留下您的邮箱地址</p> </div> <div class="dotted"></div> <div class=""> <label><font color="#FF0000">*</font>希望代理区域:</label> <c:choose> <c:when test="${frontBusinessGyDetail.businessGy.gyArea eq '全国'}"> <p class="diquliebiao"> <input class="ipt" id="msgArea" name="businessMsg.msgArea" type="text" onchange="validateForm()" /> </p> <p class="tips" style="display:none">请选择代理地区</p> </c:when> <c:otherwise> <p class="diquliebiao"> <c:forEach items="${fn:split(frontBusinessGyDetail.businessGy.gyArea, ',')}" var="area"> <input class="ckbox" id="msgArea" name="businessMsg.msgArea" type="checkbox" value="${area}" onchange="validateForm()"/> ${area} </c:forEach> </p> <p class="tips" style="display:none">请选择代理地区</p> </c:otherwise> </c:choose> </div> <div class="dotted"></div> <div class="liuyanxinxi"> <label><font color="#FF0000">*</font> 留言信息:</label> <p class="formbox"> <textarea class="textarea" id="msgContent" name="businessMsg.msgContent" cols="" rows="" onblur="validateForm()"></textarea> </p> <p class="tips" >请输入您的留言信息</p> </div> <div class="btnBox"><a href="#" id="ajax_save_msg">提交留言</a></div> </div> </dd> </dl> <input id="reset" name="" type="reset" style="display:none;" /> </form>
在struts后台代码
XXXXX 对象 get/set略。 struts提供的 类型拦截器会自动 赋值给XXX对象 @Action(value = SAVE_AJAX_ACTION) public void save() { PrintWriter pw; try { //这句必须有否则,返回前台的对象是 dom objcet. ServletActionContext.getResponse().setContentType("text/html;charset=UTF-8"); pw = ServletActionContext.getResponse().getWriter(); if(null != businessMsg){ businessMsg.setMsgIp(Util.getConsumerIP(ServletActionContext.getRequest())); businessMsg.setMsgCreated(new Date()); businessMsg.setMsgRead(0); businessMsg.setMsgDelete(0); businessMsg.setMsgDnd(0); businessMsgManager.save(businessMsg); pw.write("success"); }else{ pw.write("error"); } } catch (IOException e) { log.error("bus_msg_save is error!",e); } }
ps:目前没找到josn直接转换成struts前后java对象的方法?哪位高手可指导下?
相关推荐
hhanbj 2020-11-17
81427005 2020-11-11
EdwardSiCong 2020-11-23
85477104 2020-11-17
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22
tztzyzyz 2020-07-20
83510998 2020-07-18
81463166 2020-07-17