请大家指点一下jsp关于登陆的问题,谢谢!!
winXp+jdk1.4+tomcat4.1
我想完成的功能就是:
从首页登陆后,登陆区由原来的登陆栏变成欢迎信息:欢迎你,***
如果密码和用户名不符合,就提示有错误
index.jsp登陆部分的代码如下:
<tr>
<TD bgcolor="#d079a7" align="center" height="18" width="200"><FONT
color="#FFFFFF">□ 加入会员 □</FONT></TD>
</tr>
<tr>
<td height="101" width="200">
<%String getLoginmessage=(String)session.getAttribute("loginsign");
if(getLoginmessage!="ok")
{%>
<form action="login_action.jsp" method=post>
<p align="center">
用户:<input name="logname" type="text" class="put" id="username" size=13
onFocus="this.value=''">
<br><br>
密码:<input name="logpass" type="password" class="put" id="password"
size=13 onFocus="this.value=''">
<br><br>
<input type="submit" value="login" name="login">
<input type="reset" value="重置" name="reset">
<br><br>
<A href="member\register.jsp" target="_blank"><FONT
color="#000000">用户注册</FONT></A>
<A href="member\findpass.jsp" target="_blank"><FONT
color="#000000">忘记密码</FONT></A>
<br>
</p>
</form>
<% }else{
out.println("<table width=200><tr><td width=80% align=center>欢迎您,<font
color=red>"+(String)session.getAttribute("username")+"</font>!</td><td
align=center width=20% ><a href=modify.jsp>修改密码</a></td></tr></table>");
}
%>
</td>
</tr>
处理登陆信息的代码如下:
login_action.jsp:
<%@ page contentType="text/html; charset=gb2312" language="java"
import="java.sql.*" errorPage="" %>
<jsp:useBean id="s" class="MyMobile.DBConn" scope="page"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<title>login_action</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="refresh" content="3;url=index.jsp">
</head>
<body>
<%!
String logname,logpass;
boolean loginAttempt = false;
String errorMessage = "请您登陆";
%>
<%!
public String getStr(String str)
{
try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("ISO8859-1");
String temp=new String(temp_t);
return temp;
}
catch(Exception e)
{
}
return "null";
}
%>
<%
if(request.getParameterValues("login") != null
&&request.getParameterValues("login")[0].trim().equals("登录")
&&request.getParameter("logname") != null
&&request.getParameter("logpass") != null)
{loginAttempt = true;}
if (loginAttempt) {
logname=request.getParameter("logname");
logpass=request.getParameter("logpass");
logname=getStr(logname);
logpass=getStr(logpass);
String sql="select * from myUser where username='"+logname+"' and
password='"+logpass+"'";
ResultSet rs=s.executeQuery(sql);
int rowscount=0;
try {
while(rs.next()) { rowscount++; }
}
catch(Exception e) {out.println(e);}
if(rowscount!=0)
{
errorMessage="成功登陆";
session.setAttribute("username",logname);
session.setAttribute("password",logpass);
session.setAttribute("loginsign","ok");
}
else { errorMessage="您的用户名或者密码不正确"; }
}
%>
<font size="2">3秒后自动返回……</font>
</body>
</html>
出现的情况是,我从首页登陆后,再次回到首页的时候,没有任何变化,没有错误提示,也没有欢迎信息
请大家教教小弟吧,不胜感激