求教java分页的url 问题!
做查询分页的时候 查询条件很多,点击查询后,条件就在url上不显示了!!求解,求方法
查询的条件应该随URL再传回来的。
方法1:在每个分页的链接上,都加上条件的串
方法2:分页的链接实际是改变了URL中页号,用JS改变URL中的页号,再访问此URL
index.jsp?uid=10&tid=20&keyword=myjava&pageNum=1
index.jsp?uid=10&tid=20&keyword=myjava&pageNum=2
uid=10&tid=20&keyword=myjava&pageNum=1
/**set value to request query string *value will encode in this func */ function SetValueToRQS(RQS,name,value) { if(RQS==null) return RQS; var index = RQS.indexOf("&"+name+"="); if(index==-1) { index = RQS.indexOf(name+"="); //filter the wrong find PS:uid=2; id=2 is a wrong find if(index>0) index=-1; } //if not found, add one if(index==-1) return RQS.replace("#", "")+"&"+name+"="+MyURLencoder(value);; var bIndex = RQS.indexOf("=",index); var eIndex = RQS.indexOf("&",index+1); if(eIndex==-1) eIndex = RQS.length; var bStr = RQS.substring(0,bIndex+1); var eStr = RQS.substring(eIndex,RQS.length); RQS = bStr+MyURLencoder(value)+eStr; return RQS; } function MyURLencoder(param) { if(param==null) return ""; param += ""; var myCode = "BKURLCODE"; param = param.replace(/\+/g,myCode); return encodeURI(encodeURI(param)); }
var link = 'index.jsp?uid=10&tid=20&keyword=myjava&pageNum=1'; link = SetValueToRQS(link,"pageNum",2); window.location.href = link;
/**get value from request query string*/ function GetValueFromRQS(RQS,name) { if(RQS==null) return ; var index = RQS.indexOf("&"+name+"="); if(index==-1) { index = RQS.indexOf(name+"="); if(index!=0) return ; } if(index==-1) return ; var bIndex = RQS.indexOf("=",index); var eIndex = RQS.indexOf("&",bIndex+1); if(eIndex==-1) eIndex = RQS.length; return RQS.substring(bIndex+1,eIndex); } /**remove value from request query string */ function RemoveAttributeFromRQS(RQS,name) { if(RQS==null) return RQS; var bIndex = RQS.indexOf("&"+name+"="); if(bIndex==-1) { bIndex = RQS.indexOf(name+"="); if(bIndex!=0) return RQS; } if(bIndex==-1) return RQS; var eIndex = RQS.indexOf("&",bIndex+1); if(eIndex==-1) eIndex = RQS.length; var bStr = (bIndex==0) ? "" : RQS.substring(0,bIndex); var eStr = RQS.substring(eIndex,RQS.length); RQS = bStr+eStr; if(RQS.indexOf("&")==0) RQS = RQS.substring(1,RQS.length); return RQS; } /** *change attribute of request query string *this func can change attribute's name and value or only the name, decide by the param */ function ChangeAttributeOfRQS(RQS,nameOld,nameNew,valueNew) { if(RQS==null) return RQS; //the attribute which name equel nameNew will be remove first RQS = RemoveAttributeFromRQS(RQS,nameNew); var bIndex = RQS.indexOf("&"+nameOld+"="); if(bIndex==-1) { bIndex = RQS.indexOf(nameOld+"="); if(bIndex!=0) return RQS; } if(bIndex==-1) return RQS; var eIndex = 0; if(typeof valueNew == "undefined") { eIndex = RQS.indexOf("=",bIndex+1); //only change the name } else eIndex = RQS.indexOf("&",bIndex+1); //change the name and value if(eIndex==-1) eIndex = RQS.length; var bStr = (bIndex==0) ? "" : RQS.substring(0,bIndex); var eStr = RQS.substring(eIndex,RQS.length); RQS = bStr+"&"+nameNew; if(valueNew !== undefined) RQS += "="+MyURLcoder(valueNew); RQS += eStr; if(RQS.indexOf("&")==0) RQS = RQS.substring(1,RQS.length); return RQS; }