JavaWeb 碎片积累
1.在session中取得数据
js不能直接在session中取得数据,在jsp页面中,可以混搭使用来取得数据:
var lelvel='<%=session.getAttribute(Constants.SUPPORT)%>';
2、在springmvc中返回视图和模型可以通过java程序片段取得到jsp页面中:
后台方法:
public ModelAndView findItem(PageForm pageForm,ItemServiceQo qo){
ModelAndView mv=new ModelAndView("itemservicelist");
Page<ItemServiceVo> page=this.itemGuideService.findItembyCondition(pageForm, qo);
mv.addObject("page", page);
return mv;
前台获取返回的model可通过以下方式取得:
<% Page pages=(Page)request.getAttribute("page"); %>
3.js取得请求路径:
var locaherf=new String(window.location);
通过new String作用使得locaherf是String型,可以使用substring函数:parm=locaherf.substring(locaherf.search(/\?/g)+1);
否则单纯使用var locaherf=window.location;会出现substring无法使用。
时间格式化:
Date.prototype.format = function (format) {
var o = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
"S": this.getMilliseconds()
};
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
};