要实现一个页面无刷新请求跳转的功能,在jsp点击按钮,然后跳转到后台action进行处理,并将处理结果显示在jsp页面上。
jsp页面中ajax代码:
function query(page){
var random=Math.random();
$.ajax({
url:"info.do?sign="+random,
type:'post',
data:{
'fundNameCode':encodeURI($("#fundNameCode").val()),
'bulletinType':$("#bulletinType").val(),
'beginDate':$("#beginDate").val(),
'endDate':$("#endDate").val(),
'page':page
},
success:function (data){
$('#showMsg').html(data);
}
});
}
info.do 是跳转请求的action,经过action处理后,将结果data返回到要显示的jsp,一般在jsp页面上写一个div,div的id就是上图代码中的 showMsg。jsp页面通过struts2 标签 展示
jsp页面显示action中查询的list
<s:iterator id="msg" value="#request.msglist" status="stu">
<li>
${msg.fundCode} ${msg.FundName} <s:date name="bulletinDate" format="yyyy-MM-dd"/>
</li>
</s:iterator>