前段时间遇到客户要求把登陆页面的登陆明默认填上上一次成功登陆的用户名。
遇到这个要求,刚开始的时候想用cookies做的,一次偶尔的我在Openlaszlo的论坛上看到有人介绍flash的 SharedObject对象,所有我突发奇想,想把登陆的用户名信息保存在SharedObject中,基本思路(简要)是这样的:第一次登陆的时候当然是空的,如果登陆成功的话,我就把信息保存到SharedObject中去,下次登陆的时候去取信息。关于SharedObject的你可以去baidu或者google上搜索一下,比较多。
附部分主要代码:
<method name="setCookies" args="username">
<![CDATA[
var cookie = SharedObject.getLocal('eccm_cookie_username');
cookie.data.username_cookies = username;
]]>
</method>
<method name="getCookies">
<![CDATA[
var cookie = SharedObject.getLocal('eccm_cookie_username');
if(cookie.data == null){
return '';
}
if(cookie.data.username_cookies!=null && cookie.data.username_cookies!=''){
return cookie.data.username_cookies;
}else{
return '';
}
]]>
</method>
<view y="60">
<view x="183">
<login_input height="25" id="username" width="130" maxlength="20"/>
</view>
<view x="183">
<method event="oninit">
username.setText(canvas.getCookies());
</method>
<password_input y="4" height="25" id="password" width="130" maxlength="15"/>
</view>
<simplelayout axis="y" spacing="10"/>
</view>
在登陆成功的地方调用:canvas.setCookies(username.getText());