strSql = "select * from user where username='"
+ username + "' and password='" + password + "'";楼主这样验证会有漏洞的哦

解决方案 »

  1.   

    你的数据源配错了,我给你一个例子看看行不行
    <data-sources>
    <data-source key="mysqlDB" type="org.apache.commons.dbcp.BasicDataSource">
    <set-property property="driverClassName" value="org.gjt.mm.mysql.Driver"/>
    <set-property property="url" value="jdbc:mysql://localhost/education"/>
    <set-property property="maxActive" value="5"/>
    <set-property property="username" value="root"/>
    <set-property property="password" value=""/>
    <set-property property="autoCommit" value="true"/>
    </data-source>
    </data-sources>下面是调用的例子public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    LoginForm loginForm = (LoginForm) form;
    String userName = loginForm.getUserName();
    String password = loginForm.getPassword();

     //通过上下文取得数据源
    //ServletContext context = servlet.getServletContext();
    //DataSource dataSource = (DataSource) context.getAttribute("mysqlDB");
    //通过request请求取得数据源,在有一个数据源时可以不用第二个参数
    DataSource dataSource = this.getDataSource(request,"mysqlDB");
    Connection conn = null;
    DBConnectionPool pool = new DBConnectionPool(dataSource);
    String turnPage = null;
    HttpSession session = request.getSession();
    session.setAttribute(Constant.USERKEY, loginForm);
    try {
    String sql = "select name from addressbook where name=? and password=?";
    conn = pool.getConnection();
    DBManager manager = new DBManager(conn, sql);
    manager.set(1, userName);
    manager.set(2, password);
    manager.execute();
    if (manager.next()) {
    turnPage = Constant.LOGINSUCCESS;
    } else {
    ActionMessages errors = new ActionMessages();
    errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
    "login.error"));
    if(!errors.isEmpty())
    {
    saveErrors(request,errors);
    }
    turnPage = Constant.LOGINFAILER;
    //turnPage = mapping.getInput();
    }
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    if (conn != null)
    pool.closeConnection(conn);
    }
    return mapping.findForward(turnPage);
    }
      

  2.   

    我怎么找不到DBConnectionPool和DBManager这两个类阿  ??