日期:2014-05-18  浏览次数:20694 次

如何在页面中判断是否登陆!
如何在页面中判断是否登陆!并且
如果登陆就隐藏登陆的那一块!如果没有登陆就显示登陆的那一块!
(网页上部分是显示的记录,下面有一个提示要登陆模块,在选择了记录后,如果没有登陆就提示要登陆,如果登陆了就是显示:“下一步”这样一个按钮。)

------解决方案--------------------
给你写了几个方法你试一下,希望能帮到你
String username = request.getParameter( "username ").trim
String password = request.getParameter( "userpassword ").trim();
if(username!=null&&!username.equals( " "))
{
if(checkLogin(username,password))
{
session.setAttribute( "username ",username);
response.sendRedirect( "login.jsp ");

}
else
{
out.print( " <script> ");
out.print( "alert( '用户名或密码错误,请重新登录 '); ");
out.print( "history.go(-1); ");
out.print( " </script> ");
}
}


//////////////////////////////////////////////////
上面调用的方法
public boolean checkLogin(String userName, String pwd)// 判断登录是否准确
{
boolean flag = false;
String sql = " ";
String selectUserName = " ";
try {
SqlserverDBConnection dbc = new SqlserverDBConnection();
sql = "select username from TB_user where username= ' " + userName
+ " ' and password= ' " + pwd + " ' ";
ResultSet rs = null;
rs = dbc.executeQuery(sql);
while (rs.next()) {
selectUserName = rs.getString( "username ");
}
rs.close();
dbc.close();
if (selectUserName.equals(userName.toString())) {
flag = true;
}


} catch (Exception e) {
// TODO: handle exception
}
return flag;
}
///////////////////////////////////////////////////////////////////////////////
然后使用filter

if(session.getAttribute( "name ")==null || session.getAttribute( "name ")== " ")
{
Functions share = new Functions();
response.sendRedirect(share.getProperties( "sendUrl "));
}
else
{
fc.doFilter(req,res);
}