楼主 可以去 www.bjsxt.com 这里看看 下个视频 里面有源码的

解决方案 »

  1.   

    http://www.family168.com/tutorial/jsp/html/
    自己跟着学源码没有
      

  2.   

    迷糊  作业吧  我也做过 建议自己做吧  要不以后让你改用Struts+Jsp你还是不会啊
      

  3.   

    CSDN上有很多
    http://download.csdn.net/source/1399174
      

  4.   

    其他观点上面的各位都说完了,我只能说,这是J2SE板块,LZ的作业时WEB的,你发错版了
      

  5.   

    在web.xml里面配置下LoginServlet,下面是LoginServlet的代码import java.io.IOException;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.Statement;import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;import com.szty.hllsys.DBConnectionManage;
    public class LoginServlet extends HttpServlet
    {
    public LoginServlet()
    {
    super();
    } public void destroy()
    {
    } public void init() throws ServletException
    {
    } public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
    this.doPost(request, response);
    } public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
    response.setContentType("text/html; charset=gb2312");
    RequestDispatcher rd;
    String pwd = request.getParameter("pwd");
    String loginname = request.getParameter("loginname");
    loginname = new String(loginname.getBytes("ISO8859-1"), "GBK"); String password = request.getParameter("pwd"); UserBean user = new UserBean();
    user.setUsername(loginname);
    user.setPassword(password); HttpSession session = request.getSession(true); Connection conn = null;
    String flag = "0";//0 成功  1 失败
    try
    {
    if (checkUser(conn, loginname, password))
    {
    session.setAttribute("loginname", loginname);
    session.setAttribute("password", password);

    rd = request.getRequestDispatcher("/index.jsp");
    rd.forward(request, response);
    flag = "0";
    return;
    }
    else
    {
    flag = "1";
    request.setAttribute("flag", flag); rd = request.getRequestDispatcher("/default.jsp");
    rd.forward(request, response); }
    }
    catch (Exception e)
    {
    e.printStackTrace();
    } } public boolean checkUser(Connection conn, String username, String password)
    throws Exception
    {
    ResultSet rs = null;
    Statement stmt = null;
    String sql = "select * from SystemUser  where username='" + username
    + "' and password='" + password + "'";
    // 获取数据库连接
    conn = DBConnectionManage.getConnection();
    stmt = conn.createStatement();
    rs = stmt.executeQuery(sql); if (rs.next())
    {
    UserBean user = new UserBean(); rs.close();
    stmt.close();
    conn.close();
    return true;
    }
    else
    {
    conn.close();
    return false;
    } } public int getUserIdByName(String username, String password)
    throws Exception
    {
    ResultSet rs = null;
    Statement stmt = null;
    Connection conn=null;
    String sql = "select userId from SystemUser  where username='" + username
    + "' and password='" + password + "'";
    // 获取数据库连接
    conn = DBConnectionManage.getConnection();
    stmt = conn.createStatement();
    rs = stmt.executeQuery(sql);
    if (rs.next())
    {
    int userId=Integer.parseInt(rs.getString(1));
    rs.close();
    stmt.close();
    conn.close();

    return userId;
    }
    else
    {
    rs.close();
    stmt.close();
    conn.close();
    return 0;
    } }}