From http://vovanhai.wordpress.com Trong này, hướng dẫn bạn cấu hình Eclipse JavaEE tạo servlet Download Eclipse at: http://www.eclipse.org/downloads/ (Nhớ chọn version JavaEE nhé) Chạy eclipse Cấu hình server: Src: chứa source code WebContent chứa trang JSP Bạn thêm Init Params muốn Bạn sửa URL mapings muốn Các methods implements, mặc định impls doGet, doPost Code sau tạo package vovanhai.wordpress.com; import import import import import java.io.IOException; javax.servlet.ServletException; javax.servlet.http.HttpServlet; javax.servlet.http.HttpServletRequest; javax.servlet.http.HttpServletResponse; /** * Servlet implementation class LogonServlet */ public class LogonServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public LogonServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } } File config _NewFirstServlet index.html index.htm index.jsp default.html default.htm default.jsp LogonServlet LogonServlet vovanhai.wordpress.com.LogonServlet LogonServlet /LogonServlet Code sửa lại cho servlet package vovanhai.wordpress.com; import import import import java.io.IOException; javax.servlet.ServletException; javax.servlet.http.HttpServlet; javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Servlet implementation class LogonServlet */ public class LogonServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public LogonServlet() { super(); } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //ví dụ doPOst lần doGet dùng chung doPost(request, response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //lấy tham số từ người dùng String us=request.getParameter("us"); String ps=request.getParameter("ps"); //Kiểm tra username, password //Bạn đăng nhập CSDL, kiểm tra Ở để đơn giản kiêm tra us=ps không if(us.equals(ps)) request.getRequestDispatcher("success.jsp").forward(request, response); else request.getRequestDispatcher("failed.jsp").forward(request, response); } } Thiết kế trang web, Thêm trang JSP Insert title here User name: Password: Tạo trang success.jsp failed.jsp với nội dung tùy ý bạn Thực thi ứng dụng ***Chú ý : Import dự án tồn vào eclipse : Chúc thành công ! ... javax .servlet. ServletException; javax .servlet. http.HttpServlet; javax .servlet. http.HttpServletRequest; import javax .servlet. http.HttpServletResponse; /** * Servlet implementation class LogonServlet... LogonServlet LogonServlet< /servlet- name> vovanhai.wordpress.com.LogonServlet< /servlet- class> < /servlet> ... LogonServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public LogonServlet() { super(); } /** * @see HttpServlet#doGet(HttpServletRequest