当前位置: 代码迷 >> J2EE >> 使用<jsp:userBean>时scope不对解决思路
  详细解决方案

使用<jsp:userBean>时scope不对解决思路

热度:691   发布时间:2016-04-17 23:05:16.0
使用<jsp:userBean>时scope不对
在下面这段代码中,我从cookie中读取到用户名以及密码,打算在用户下次登录时,直接填写上,不用用户再手动输入。但是却始终出现在这个scope找不到userNameAndPassword这个bean,不知道是什么原因。我把scope改成application也不管用。请大牛指教。
下面是代码:
<jsp:useBean id="userNameAndPassword" type="com.javaBean.UserNameAndPasswordBean" scope="request">
<form action="/WebRoot/CheckAccount" class="login" >
<label for="account" class="labelStyle">&nbsp;账号</label>
<input type="text" name="account" class="inputBoxStyle" id="userAccount" value='<jsp:getProperty name="userNameAndPassword" property="userName" />'/>

<!-- 这里必须是name才能在url后面接上完整的键值对 -->
<br />
<br />
<label for="password" class="labelStyle">密码&nbsp;</label>
<input type="password" name="password" class="inputBoxStyle"/>
<br />
<br />
<a href="register.jsp">没有账号?注册一个吧</a>
<br />
<input type="submit" value="登录"/>

</form>
</jsp:useBean>

------解决思路----------------------
在Servlet中加上类似这样的代码:

UserNameAndPasswordBean userNameAndPassword = xxxxxxxxx;
request.setAttribute("userNameAndPassword", userNameAndPassword);

------解决思路----------------------
XXservlet中设置request的attribute,然后servlet直接重定向forward到登陆页面,是这样吗?如果不是,就改吧
  相关解决方案