<%@ 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  请问  如何在这个登陆界面上写代码 急!我是初学!

解决方案 »

  1.   

    login_do.jsp
    得到参数name, pwd
    然后去数据库验证
    还是好好学习吧 
      

  2.   

    login_do  这个页面上判断就可以了.取出NAME和PWD的值...如果嫌麻烦的话,用AJAX来判断也行...(AJAX安全性MS不太好.)
      

  3.   


    <%
      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可以参考下...
      

  4.   

    你要在登录界面上写什么代码?还是在login_do.jsp上写
      

  5.   

    写一个连接数据库的jsp页面,连接到那验证
      

  6.   

    不要在这个登录页面上写java代码
      

  7.   

    登陆界面上不要写JAVA代码。。
    在login_do.jsp里面 
    String name=request.getParameter("user_name").trim();        
    String pwd=request.getParameter("user_psd").trim();
    然后连接数据库验证。再根据结果返回对应的页面就行了。。