This post explains how to build a Login application in Java using MVC and MySQL database which uses JSP, Servlets, Beans, DAOs and HTML pages. This login application follows standard Model View Controller(MVC) design pattern.
The model(DAO) consists of application data and business rules, and the controller(Servlet) mediates input, converting it to commands for the model or view. A view(JSP) can be any output representation of data, such as a chart or a diagram, generally an html or jsp page.Here DAO is the Data Access Object – It mainly contains business logic with database connections and operations.Use any IDE – Integrated development environment to minimize your work. I would recommend you Eclipse for Java.This application is explained thoroughly with appropriate comments and tested in Eclipse IDE. Please write comments if you find any difficulty while understanding the application.
You need to maintain the standard directory structure as shown below
Login details are forwarded to LoginServlet from Login page. When you click on Login button the request is forwarded to the page which is mentioned in action tag of the form so here the control will be forwarded to LoginServlet.java file.
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | < meta http-equiv = "Content-Type" content = "text/html; charset=ISO-8859-1" > < title >Login</ title > < form name = "form1" action = "LoginServlet" method = "post" > //Error message display in case of wrong credentials. This reply will come from LoginServlet.java < table align = "center" > < tbody >< tr class = "alt" > < td >Username</ td > < td >< input type = "text" name = "username" ></ td > </ tr > < tr > < td >Password</ td > < td >< input type = "text" name = "password" ></ td > </ tr > < tr class = "alt" >< td ><%=(request.getAttribute("errMessage") == null) ? "" : request.getAttribute("errMessage")%></ td > </ tr > < tr > < td ></ td > < td >< input type = "submit" value = "Login" >< input type = "reset" value = "Reset" ></ td > </ tr > </ tbody ></ table > </ form > < script type = "text/javascript" src = "//ajax.cloudflare.com/cdn-cgi/nexp/dok3v=73806ac11c/apps1.min.js" ></ script >< script type = "text/javascript" >__CF.AJS.init1();</ script > |
The Error message is displayed on the Login page for invalid user credentials. If you do not understand about error message display just ignore it. It won;t affect your application.
Read More >> Login application in Java using MVC and MySQL
No comments:
Post a Comment