JAVA编程:浏览器的cookie问题 根据你的要求你应该用Session在你验证完用户后把用户名存放在session里,下次登陆jsp时候先验证下session中是否存在用户if (验证成功 ){ session.setAttribute("username",username);}jsp里String username= session.getAttribute("username");if (!"".equls(username) || username==null){ 跳转到登陆jsp..} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你应该用Session,当你严正完用户正确后把他存放在Session里if (严正成功){ session.setAttribute("user",user);}在jsp上加入{ User user = (User)session.getAttribute("user"); if (user==null) { 跳转到登陆jsp }} 首先谢谢你的回复!其次我补充一下,我是用Ajax验证用户名与密码,我是将页面的值传给一个js,在js中把值传给后台,通过后台验证用户名与密码是否正确,最后将文本结果返回给js,js将结果显示在页面的<div>上。用了您的方法,request.getSession().setAttribute("userslogin", userslogin);(我是写在struts的action中的),但这个如何返回到js中去呢?我这么写了,页面端的代码是:<table width="730" border="0"> <tr> <td> <div id="user_request"> <% Userslogin userslogin = (Userslogin) request .getAttribute("userslogin"); if (userslogin != null) { %> abc <% } else { %> <table> <tr> <td width="220"> 用户名: <input type="text" id="username" name="password" width="50"> </td> <td width="500"> 密码: <input type="password" id="password" name="password" width="20"> <input type="button" value="登陆" onclick="verify()"> <a href="<%=request.getContextPath()%>/pages/register.jsp">注册</a> </td> </tr> </table> <% } %> </div> </td> </tr> </table>可是不行。请指教! <%Userslogin userslogin = (Userslogin) session.getAttribute("userslogin");if (userslogin != null) {%> 大哥,你就是我的救命恩人!的确,我忘记用session取了,换了session就ok了!万分感谢! 那请问如果想删除session里的值(访退出功能),在不关闭网页的情况下如何操作? 同样的程序,debug就出现正确结果,run就不出。怎么回事? tomcat 6 移植到 jboss 5问题多多 这段schema的疑问 关于连接池自动创建新连接问题 pager-taglib 做分页 show_sql到底要加在哪啊,我加上就提示错误 各位大侠们 我用了acegi框架登陆 做了个验证码 当我输入正确的验证码时他还会报错 希望大侠们帮帮忙 !谢谢了 !急。。。。 struts2中ognl的问题 公司员工的对象如何建模 使用FtpClient上传Spring MVC找不到该类 高分求救,怎样提取字符串中的数据 FormBean
if (严正成功)
{
session.setAttribute("user",user);
}
在jsp上加入
{
User user = (User)session.getAttribute("user");
if (user==null)
{
跳转到登陆jsp
}
}
用了您的方法,request.getSession().setAttribute("userslogin", userslogin);(我是写在struts的action中的),但这个如何返回到js中去呢?我这么写了,页面端的代码是:
<table width="730" border="0">
<tr>
<td>
<div id="user_request">
<%
Userslogin userslogin = (Userslogin) request
.getAttribute("userslogin");
if (userslogin != null) {
%>
abc
<%
} else {
%>
<table>
<tr>
<td width="220">
用户名:
<input type="text" id="username" name="password"
width="50">
</td>
<td width="500">
密码:
<input type="password" id="password" name="password"
width="20">
<input type="button" value="登陆" onclick="verify()">
<a
href="<%=request.getContextPath()%>/pages/register.jsp">注册</a>
</td>
</tr>
</table>
<%
}
%>
</div>
</td>
</tr>
</table>可是不行。请指教!
<%
Userslogin userslogin = (Userslogin) session.getAttribute("userslogin");
if (userslogin != null) {
%>