本人近期正在做一个网上购书系统,用的是asp+sql+eclipse+tomca ,在做用户登录页面的时候需要将输入的数据跟数据库中的内容匹配,成功的话就跳转到登录成功页面,想知道怎么写这个checkuser的代码?还有就像管理员可以插入删除修改数据库中的数据也要连接数据库,怎么写啊?我现在连接了数据库,只能查看数据库中的内容,还不会修改?
请高手指点,小女子先谢谢了!

解决方案 »

  1.   

    这个不是很容易,写个查询语句,看有没有记录了。
    修改记录要用update语句的。
      

  2.   

    sql的查询语句会写
    可关键是它在jsp中肯定还要写其他的语句
    具体怎么跟数据库连接我就不会了
    还请高手指点
      

  3.   

    这是我的getuser.jsp <%@ page language="java" contentType="text/html; charset=UTF-8"%>
    <%@page import="shopping.db.*,java.sql.*" import ="java.sql.PreparedStatement" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <jsp:useBean id="getsuers" class="shopping.entity.User" scope="page">
    </jsp:useBean>
    <%//提交信息后,验证是否正确
      String name = "";
          String number = "";
          String password = "";
          String role = "";
          String birthday = "";
          String sex = "";
          
    //if(!(session.isNew())){
    name=request.getParameter("name");
    if(name==null) name="";

    number=request.getParameter("number");
    if(number==null) number=""; password=request.getParameter("password");
    if(password==null) password="";

    role=request.getParameter("role");
    if(role==null) role="";

    birthday=request.getParameter("birthday");
    if(birthday==null) birthday="";

    sex=request.getParameter("sex");
    if(sex==null) sex="";
    //}
    %>
    <%
    if(name.equals("")&&!number.equals("")&&!password.equals("")
    &&!rple.equals("")&&!birthday.equals("")&&!sex.equals(""))
    %>
    <jsp:useBean id="getsuers" class="shopping.entity.User" scope="page" action="checkuser.jsp">
    <jsp:setProperty name="student" property="*"/>
    </jsp:useBean>
    <%  boolean flag=register.register(getuers);
              if(flag){
              response.sendRedirect("sloginsueccess.jsp");
              }else {
              response.sendRedirect("studentlogin.jsp");
              }
              %>
                <html>
    <head>
    <title>Insert title here</title>
    </head>
    <body bgcolor="#ffffff">
    <SCRIPT language="javascript">
    alert("用户名或密码错误,请重新登录");
    window.location = "studentlogin.jsp";
    </SCRIPT>
    <h1>
    </h1>
    </body>
    </html>
      

  4.   

    使用name和password 作为查询条件连接数据库,当结果返回一条时,表示登录成功,将用户信息封装保存至session范围保证本次回话结束前该用户信息可以在任何地方访问.否则为失败,弹出错误提示,范围登录
      

  5.   

    用户登陆成功用session保存用户信息,否则提示错误信息,在每个页面都进行判断
    你可以用包含也可以做个过滤器,这样用户就控制好了
    if(用户验证成功){
         session.setAttribute("user",user);
          response.sendRedirect("sloginsueccess.jsp"); 
    }在其他页面每次进行判断:User user=(User)session.getAttribute("user");
    if(user==null){//不是登陆用户,跳转到登陆页面
         response.sendRedirect("login.jsp"); 
    }else{
        //执行下面的操作
    }上面的代码可以单独做个页面,其他的只要包含就可以,如:validateUser.jsp
    至于管理员执行增删改的操作,只需要写相应的SQL语句,调用相应的逻辑即可,
      

  6.   

    有没有搞错?tomcat里跑asp?????
    先装个IIS吧
      

  7.   


    checkuser ——首先要会SQL语句!string sql="select * from users where name=? and pwd=?";
    通过查询结果判断,如果为空则,不存在该用户无法登陆成功!不为空则登录进去!插入insert into 修改update!
      

  8.   

    呵呵,你最好是先用小脚本写吧,这样混乱搞得头昏眼花的,写好了再改成你想要的<jsp>动作
      

  9.   


    不好意思各位 是用的JSP  之前打错了 
      

  10.   

    我有个和你一样的程序,用JSP写的 你调一下 
    登陆(login.jsp)
     
    <%@ page contentType="text/html;charset=GB2312"%>
    <html>
    <head>
    <title>书店租书管理系统</title>
    </head>
    <body bgcolor="#DCDADA">
    <table border="0" width="100%" height="173">
    <tr>
    <td height="40">
    &nbsp;
    </td>
    </tr>
    <tr>
    <td width="100%" height="34">
    <p align="center">
    <font size="6"><b>书店租书管理系统<font size="4">(软件061
    )</font> </b> </font>
    </td>
    </tr>
    <tr>
    <td width="100%" height="21">
    <p align="center">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    ————软件061-13-张文琛!
    </td>
    </tr>
    </table>
    <form action="checkLogin.jsp" method="POST">
    <table align="center" border="0">
    <tr align="center">
    <td>
    <font color="red"><html:errors /> </font>
    </td>
    </tr>
    <tr align="center">
    <td>
    系统登录
    </td>
    </tr>

    <tr>
    <td>
    用户卡号:
    <input type="text" name="cardno">
    </td>
    </tr>
    <tr>
    <td>
    密&nbsp;&nbsp;&nbsp;&nbsp;码:
    <input type="password" name="passwd">
    </td>
    </tr>
    <tr>
    <td>
    角&nbsp;&nbsp;&nbsp;&nbsp;色:
    <select name="role">
    <option value="1">
    普通管理员
    </option>
    <option value="2">
    高级管理员
    </option>
    <option value="3">
    普通用户
    </option>
    <option value="4">
    高级用户
    </option>
    </select>
    </td>
    </tr>
    <tr align="center">
    <td>
    <input type="submit" value="确定" name="submit">
    </td>
    </tr>

    </table>
    </form>
    </body>
    </html>
    检查页面(checkLogin.jsp)
    <%@ page contentType="text/html;charset=GBK"language="java" import="java.sql.*" import="java.util.*" %>
    <%@ include file="conn.jsp"%>
    <html>
    <body>
    <%
    request.setCharacterEncoding("GBK");
     String  acardno=request.getParameter("cardno");
     String   apasswd=(String)request.getParameter("passwd");
     String    arole=(String)request.getParameter("role");
      
        if(arole.equals("1")||arole.equals("2")){
             ResultSet rs=stmt.executeQuery("select * from manager where cardno='"+acardno+"' and passwd='"+apasswd+"'");
             if(rs.next()){
                 session.putValue("cardno",acardno);
                 session.putValue("passwd",apasswd);
                 session.putValue("role",arole);
                 response.sendRedirect("manager.jsp");
               } 
               rs.close();
           }
        if (arole.equals("3")||arole.equals("4")){
         ResultSet rs=stmt.executeQuery("select * from user where cardno='"+acardno+"' and passwd='"+apasswd+"'");
               if(rs.next()){
                 session.putValue("cardno",acardno);
                 session.putValue("passwd",apasswd);
                 session.putValue("role",arole);
                 response.sendRedirect("user.jsp");
               } 
               rs.close();
          }
         
      stmt.close();
      con.close();
      
     %>
    </body>
    </html>
      

  11.   


    老兄啊,不要害人,你这样会导致sql注入的。
      

  12.   

    用getparament得到的usernam and password进行查询,得到结果集resultset,再循环查这个结果集,如果结果集中存在数据就行了。
      

  13.   

    大家看我的checkuser.jsp
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@page import="shopping.db.*,java.sql.*"%>
    <%@page import="shopping.entity.*"%>
    <%@page import="shopping.imp.*"%>
    <%@page import="shopping.inter.*" %><jsp:useBean id="DB" class="shopping.db.DB"></jsp:useBean>
    <jsp:useBean id="User" class="shopping.entity.User" scope="session"></jsp:useBean>
    <jsp:setProperty name="User" property="*" />
    <html>
    <head> <TITLE>****网上购书系统</TITLE>
    <META http-equiv=Content-Language content=zh-cn>
    <META http-equiv=Content-Type content="text/html; charset=UTF-8">
    <LINK href="images/enter.css" type=text/css rel=stylesheet>
    </head> <body>
    <BODY style="BACKGROUND-IMAGE: url(images/2e_bg.jpg)">
    <DIV align=center>
    <TABLE style="BORDER-COLLAPSE: collapse" height=576 cellPadding=0
    width=990 border=0>
    <TR>
    <TD width=230>
    <!--   leftindex.html -->
    <%@include file="leftindex.jsp"%>
    <!-- end leftindex.html -->
    </TD> <TD width="677" valign="top"> <table width="656" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td height="10" colspan="3"></td>
    </tr>
    <tr>
    <td colspan="3">
    <img src="images/33e_top1.jpg" width="656" height="17">
    </td>
    </tr>
    <tr>
    <td colspan="3">
    <img src="images/33e_top11.jpg" width="656" height="34">
    </td>
    </tr>
    <tr>
    <td width="2%">
    <IMG height=519 src="images/33e_left.jpg" width=13 border=0>
    </td>
    <td width="95%" align="center" valign="top" bgcolor="#FFFFFF">
    <!-- bannerindex.html  -->
    <%@include file="bannerindex.jsp"%>
    <!-- end  bannerindex.html  --> <!-- main.jsp  -->
    <h2>
    用户登录验证
    </h2>
    <%
    String name = User.getName();
    String password = User.getPassword();
    boolean  isLogined= false;

    String sql = "select * from User where name='" + name
    + "' and password ='" + password + "'";
    String message  = null;ResultSet rs    = null ;
    Connection conn = DB.getConn();
    Statement stmt  = DB.createStmt(conn);

    rs = stmt.executeQuery(stmt,sql) ;
    if (rs.next()) {
    message = "您已经登录过了!";isLogined = true ;
    } else { ResultSet rs = DB.executeQuery(stmt, sql);
    if (rs.next()) {
    User.setLogined(true);
    message = "恭喜您,登录成功!";
    response.sendRedirect(request.getContextPath()
    + "/sloginsueccess.jsp"); } else {
    User.setLogined(false);
    message = "用户名或密码错误,请重新登陆";
    response.sendRedirect(request.getContextPath()
    + "/loginfail.jsp"); }
    }
    %> <!-- end main.jsp -->
    </td>
    <td width="3%">
    <img src="images/33e_right.jpg" width="21" height="519">
    </td>
    </tr>
    <tr>
    <td colspan="3">
    <img src="images/33e_down.jpg" width="656" height="15">
    </td>
    </tr> </table>
    </td>
    <TD width=85>
    <!--  tagindex.jsp   -->
    <%@include file="tagindex.jsp"%>
    <!--   end tagindex.jsp  -->
    </TD>
    </TR>
    </TABLE>
    </DIV> <!--  footindex.jsp        -->
    <%@include file="footindex.jsp"%>
    <!--  end footindex.jsp  -->
    </body>
    </html>
      

  14.   

     jsp里面有java代码啊?很乱的,为什么不用MVC框架呢?那样层次更清晰。