E đã code lại cái ví dụ của ban ở Hòa Bình...mà sao nó cứ hiện ra lỗi....
đây là phần cop code của em...mọi người cho ý kiến nhá..
Đây là index
Mã:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login</title>
</head>
<body>
<h1>Đăng Nhập</h1>
<form action="=Controller" method="post">
Tài Khoản <input type="text" name="txtUsername" value=""><br/>
Mật Khẩu <input type="password" name="txtPass" value=""><br/>
<input type="submit" value="Login" name="btAction">
<input type="reset" value="Reset">
</form>
</body>
</html>
Đây là LoginBean
Mã:
public class LoginBean implements Serializable{
public LoginBean(){
}
public boolean checkLogin(String username, String password)
{
try
{
Connection con = null;
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/demoweb?zeroDateTimeBehavior=convertToNull";
con=DriverManager.getConnection(url);
String sql="select username,password from admin where username='"+username+"'and password ='"+password+"'";
Statement stm=con.createStatement();
ResultSet rs=stm.executeQuery(sql);
boolean result=rs.next();
if(result)
{
return true;
}
rs.close();
stm.close();
}catch(Exception e)
{
e.printStackTrace();
}
return false;
}
}
Đây là Controller
Mã:
public class Controller extends HttpServlet{
final private String errorPage="fail.jsp";
final private String homePage="index.jsp";
final private String welcomePage="welcome.jsp";
public void processRequest(HttpServletRequest request,HttpServletResponse response) throws IOException, SQLException, ServletException
{
response.setContentType("text/html;charset=UTL-8");
PrintWriter out=response.getWriter();
String action=request.getParameter("btAction");
if(action.equals("Login"))
{
String username=request.getParameter("txtUsername");
String password=request.getParameter("txtPass");
LoginBean login=new LoginBean();
boolean result=login.checkLogin(username, password);
String url=errorPage;
if(result)
{
HttpSession session=request.getSession(true);
session.setAttribute("User", username);
url=welcomePage;
RequestDispatcher rd=request.getRequestDispatcher(url);
rd.forward(request, response);
}
}
}
}
Mong mọi người tim lỗi giúp em với
đây là phần cop code của em...mọi người cho ý kiến nhá..
Đây là index
Mã:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login</title>
</head>
<body>
<h1>Đăng Nhập</h1>
<form action="=Controller" method="post">
Tài Khoản <input type="text" name="txtUsername" value=""><br/>
Mật Khẩu <input type="password" name="txtPass" value=""><br/>
<input type="submit" value="Login" name="btAction">
<input type="reset" value="Reset">
</form>
</body>
</html>
Đây là LoginBean
Mã:
public class LoginBean implements Serializable{
public LoginBean(){
}
public boolean checkLogin(String username, String password)
{
try
{
Connection con = null;
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/demoweb?zeroDateTimeBehavior=convertToNull";
con=DriverManager.getConnection(url);
String sql="select username,password from admin where username='"+username+"'and password ='"+password+"'";
Statement stm=con.createStatement();
ResultSet rs=stm.executeQuery(sql);
boolean result=rs.next();
if(result)
{
return true;
}
rs.close();
stm.close();
}catch(Exception e)
{
e.printStackTrace();
}
return false;
}
}
Đây là Controller
Mã:
public class Controller extends HttpServlet{
final private String errorPage="fail.jsp";
final private String homePage="index.jsp";
final private String welcomePage="welcome.jsp";
public void processRequest(HttpServletRequest request,HttpServletResponse response) throws IOException, SQLException, ServletException
{
response.setContentType("text/html;charset=UTL-8");
PrintWriter out=response.getWriter();
String action=request.getParameter("btAction");
if(action.equals("Login"))
{
String username=request.getParameter("txtUsername");
String password=request.getParameter("txtPass");
LoginBean login=new LoginBean();
boolean result=login.checkLogin(username, password);
String url=errorPage;
if(result)
{
HttpSession session=request.getSession(true);
session.setAttribute("User", username);
url=welcomePage;
RequestDispatcher rd=request.getRequestDispatcher(url);
rd.forward(request, response);
}
}
}
}
Mong mọi người tim lỗi giúp em với