//设置弹出窗口
function showCity(){
//window.open("cityselect.html", "新窗口标题", "height=380, width=580, top=100, left=250, toolbar=0,menubar=0, scrollbars=0,resizable=0,location=0, status=0");
var modeldialogparam='dialogWidth:400px;dialogHeight:300px;dialogTop=0px;dialogLeft=0px;edge:raised;help:no;resizable:yes;scroll:yes;status:no';
varresult=window.showModalDialog("cityselect.html","请选择城市",modeldialogparam);
//alert(result);
if(result!=""){
var cityItem=result.split(",");
document.forms[0].cityid.value=cityItem[0];
document.forms[0].city.value=cityItem[1];
}
}
Session.getAttibute(“name”)à获得的值是一个Object对象
Session.setAttibute(“currentUser”,users);获得的值第一个为字符串,第二个是一个Object对象
UseBean类
private String usename;
private String password;
public String getUsename() {
returnusename;
}
publicvoid setUsename(String usename) {
this.usename = usename;
}
public String getPassword() {
returnpassword;
}
publicvoid setPassword(String password) {
this.password = password;
}
(1).在Java类(类Login)继承session中—>把一个对象存到session 中;
//把要存放对象的session名设成一个静态的常量CURRENTUSER 因为session 每个用户只//创建一次只在第一次用的时候实例化
Public static String CURRENTUSER=”currentUser”;
UseBean users = new UseBean();
users.setUsename(name);
users.setPassword(pass);
//把一个对象存到session 中首先建一个session 对象
HttpSession session=request.getSession();
Session.setAttribute(CURRENTUSER,users);
(2)在另一个类中取得这个session 的值
//同样先创建session
HttpSession session =hrequest.getSession();
Session.getAttribute();
UseBean bean=null;
If(session.getAttribute(Login. CURRENTUSER)!=null){
//把session取得Object转化成UseBean 类型
Bean=(UseBean)session.getAttribute(Login. CURRENTUSER);
//取得session 中的name值:
Bean. getUsename();
}