<%@ page contentType="text/html;charset=gbk"%><html>
<head>
<title></title>
</head>
<body>
<div align="right"><a href="regist.jsp">注册新用户</a></div>
<center>
<h2>
<font color="red">用户登陆</font>
</h2>
<form action="login_do.jsp" method="post">
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td>用户名:</td>
<td><input type="text" name="name" size = "21"/></td>
</tr>
<tr>
<td> 密 码:</td>
<td><input type="password" name="pwd" size="21"/></td>
</tr>
<tr align="center">
<td colspan="2">
<input type="submit" value="登陆"/>
<input type="reset" value="取消"/>
</td>
</tr>
</table>
</form>
<%
if(request.getAttribute("login_mess")!=null){
%><div><%=request.getAttribute("login_mess") %></div><%
}
%>
</center>
</body>
</html>
这个是登陆界面,假如连接数据库的验证数据库信息方法的界面是login_do 请问 如何在这个登陆界面上写代码 急!我是初学!
<head>
<title></title>
</head>
<body>
<div align="right"><a href="regist.jsp">注册新用户</a></div>
<center>
<h2>
<font color="red">用户登陆</font>
</h2>
<form action="login_do.jsp" method="post">
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td>用户名:</td>
<td><input type="text" name="name" size = "21"/></td>
</tr>
<tr>
<td> 密 码:</td>
<td><input type="password" name="pwd" size="21"/></td>
</tr>
<tr align="center">
<td colspan="2">
<input type="submit" value="登陆"/>
<input type="reset" value="取消"/>
</td>
</tr>
</table>
</form>
<%
if(request.getAttribute("login_mess")!=null){
%><div><%=request.getAttribute("login_mess") %></div><%
}
%>
</center>
</body>
</html>
这个是登陆界面,假如连接数据库的验证数据库信息方法的界面是login_do 请问 如何在这个登陆界面上写代码 急!我是初学!
得到参数name, pwd
然后去数据库验证
还是好好学习吧
<%
String username=request.getParameter("user_name").trim();
String password=request.getParameter("user_psd").trim();
boolean login=user.Login(username,password1);//查看是否通过验证
if(login){
session.setAttribute("user_name",username);
session.setAttribute("loginmess","loginsuccess");
response.sendRedirect("index.jsp");
}else{
session.setAttribute("loginmess","loginfail");
response.sendRedirect("error.jsp?id=4");//用户名密码不正确
}
%>
public boolean Login(String username,String password){//登录
boolean loginok=false;
ResultSet rest=null;
try {
rest=stmt.executeQuery("select * from Users where user_name = '"+username+"' and user_psd = '"+password+"'");
if(rest.next()){
loginok=true;
}else{
loginok=false;
}
} catch (SQLException ex) {
ex.printStackTrace();
int i=ex.getErrorCode();
}
finally{
this.close();
}
return loginok;
}
我的login方法是在bean中实现的,代码lz可以参考下...
在login_do.jsp里面
String name=request.getParameter("user_name").trim();
String pwd=request.getParameter("user_psd").trim();
然后连接数据库验证。再根据结果返回对应的页面就行了。。