{"id":151,"date":"2018-07-11T10:00:14","date_gmt":"2018-07-11T10:00:14","guid":{"rendered":"http:\/\/itp16.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=151"},"modified":"2019-05-15T07:30:34","modified_gmt":"2019-05-15T07:30:34","slug":"developing-web-application-using-mvc-1","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/chapter\/developing-web-application-using-mvc-1\/","title":{"rendered":"Developing Web Application Using MVC -1"},"content":{"raw":"<div><span style=\"float: right;\"><a href=\"https:\/\/youtu.be\/d7HUdb2UEWQ\" target=\"_blank\" rel=\"noopener\"><img src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a>\r\n<\/span><\/div>\r\n<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\"><strong>Introduction<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">In the last module, we have learnt about MVC architecture for development of Web applications.. This development of web application using MVC has been divided into two modules. This is the first module for developing web application using MVC. In this module we develop the required Model classes.<\/p>\r\n&nbsp;\r\n<p class=\"hanging-indent\" style=\"text-align: justify;\"><strong>Demo Of creating Web application Using MVC part 1.\u00a0<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">In this demo we will develop the Model class for our web application. The following classes have been identified for development in this module..<\/p>\r\n\r\n<ul style=\"text-align: justify;\">\r\n \t<li>A <strong>UserInfo <\/strong>class, which is a simple Java bean class for storing information about a User.<\/li>\r\n \t<li>A <strong>A<\/strong><strong>uthenticator <\/strong>class, which will be used for authenticating. The class with the logic for authenticating the credentials<\/li>\r\n \t<li>A <strong>M<\/strong><strong>e<\/strong><strong>ssageBean <\/strong>class, which is a simple Java Bean class for storing a message String.<\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify;\"><strong>Developing the UserInfo class\u00a0<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The User class is a Simple Java Bean class. Here it is used for storing information about a user. It has only three properties, name, email and address. The source code for UserInfo is as follows:<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Source code of UserInfoha class<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">package org.epgpathshala.dad.model;<\/p>\r\n<p style=\"text-align: justify;\">public class UserInfo { private String name; private String email; private String address; public String getName() {<\/p>\r\n<p style=\"text-align: justify;\">return this.name;<\/p>\r\n<p style=\"text-align: justify;\">}<\/p>\r\n<p style=\"text-align: justify;\">public void setName(String n) {<\/p>\r\n<p style=\"text-align: justify;\">this.name = n;<\/p>\r\n<p style=\"text-align: justify;\">}<\/p>\r\n<p style=\"text-align: justify;\">public String getEmail() { return this.email;<\/p>\r\n<p style=\"text-align: justify;\">}<\/p>\r\n<p style=\"text-align: justify;\">public void setEmail(String e) {<\/p>\r\n<p style=\"text-align: justify;\">this.email = e;<\/p>\r\n<p style=\"text-align: justify;\">}<\/p>\r\n<p style=\"text-align: justify;\">public String getAddress() { return this.address;<\/p>\r\n<p style=\"text-align: justify;\">}<\/p>\r\n<p style=\"text-align: justify;\">public void setAddress(String a) {<\/p>\r\n<p style=\"text-align: justify;\">this.address = a;<\/p>\r\n<p style=\"text-align: justify;\">}<\/p>\r\n<p style=\"text-align: justify;\">}<\/p>\r\n&nbsp;\r\n<p class=\"hanging-indent\" style=\"text-align: justify;\"><strong style=\"text-align: initial; font-size: 1em;\">Developing the Authenticator class\u00a0<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">The Authenticator class is a simple class, it used for authenticating a user. It has a method called authenticate which takes loginid and password and returns a boolean value. In this demo a simple Authenticator has been developed, which authenticates for a fixed loginid and password. It also has a method for getting the UserInfo object for a given loginid. The code for Authenticator class is as follows:<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">Source for Authenticator class<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">package org.epgpathshala.dad.model;<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">public class Authenticator {<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">public boolean authenticate(String lid, String pswd) {<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">return (lid.equals(\"guest\")) &amp;&amp; (pswd.equals(\"guest\"));<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">}<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">public UserInfo getUserInfo(String lid) { if (!lid.equals(\"guest\")) {<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">return null;<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">}<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">UserInfo info = new UserInfo();<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">info.setName(\"Guest\"); info.setEmail(\"<\/span><a style=\"text-align: initial; font-size: 1em;\" href=\"mailto:guest@epgpathsla.org\">guest@epgpathsla.org\"<\/a><span style=\"text-align: initial; font-size: 1em;\">); info.setAddress(\"Ahmedabad\");<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">return info;<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">}<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">}<\/span><\/p>\r\n&nbsp;\r\n<p class=\"hanging-indent\" style=\"text-align: justify;\"><strong style=\"font-size: 1em;\">Developing the MessageBean class<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">The MessageBean class is a simple Java Bean class, used for storing a message as a String. It has a single property called message. The code for MessageBean is as follows:<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">Source code of MessageBean class<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">package org.epgpathshala.dad.model;<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">public class MessageBean { private String message = \"\"; public String getMessage() {<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">return this.message;<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">}<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">public void setMessage(String msg) { this.message = msg;<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">}<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">}<\/span><\/p>\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td><strong>you can view video on Developing Web Application Using MVC -1<\/strong><\/td>\r\n<td><a href=\"https:\/\/youtu.be\/d7HUdb2UEWQ\" target=\"_blank\" rel=\"noopener\"><img class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p class=\"hanging-indent\" style=\"text-align: justify;\"><strong style=\"font-size: 1em;\">Suggested Reading:<\/strong><\/p>\r\n\r\n<\/div>\r\n<ol>\r\n \t<li style=\"text-align: justify;\">Expert One-on-One J2EE Development without EJB by Rod Johnson and Juergen Hoeller, Wrox publication<\/li>\r\n \t<li style=\"text-align: justify;\">Core Servlets and Java Server Pages Volume 2 by Marty Hall &amp; Larry Brown, Second Edition, Pearson Education.<\/li>\r\n \t<li style=\"text-align: justify;\">Inside Servlets by Dustin R Callaway, Pearson Education.<\/li>\r\n \t<li style=\"text-align: justify;\">Java Server Programming for Professionals by Ivan Bayross, Sharanam Shah, Cynhthia Bayross and Vaishali Shah Shroff Publishers and Distributros.<\/li>\r\n<\/ol>","rendered":"<div><span style=\"float: right;\"><a href=\"https:\/\/youtu.be\/d7HUdb2UEWQ\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a><br \/>\n<\/span><\/div>\n<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><strong>Introduction<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">In the last module, we have learnt about MVC architecture for development of Web applications.. This development of web application using MVC has been divided into two modules. This is the first module for developing web application using MVC. In this module we develop the required Model classes.<\/p>\n<p>&nbsp;<\/p>\n<p class=\"hanging-indent\" style=\"text-align: justify;\"><strong>Demo Of creating Web application Using MVC part 1.\u00a0<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">In this demo we will develop the Model class for our web application. The following classes have been identified for development in this module..<\/p>\n<ul style=\"text-align: justify;\">\n<li>A <strong>UserInfo <\/strong>class, which is a simple Java bean class for storing information about a User.<\/li>\n<li>A <strong>A<\/strong><strong>uthenticator <\/strong>class, which will be used for authenticating. The class with the logic for authenticating the credentials<\/li>\n<li>A <strong>M<\/strong><strong>e<\/strong><strong>ssageBean <\/strong>class, which is a simple Java Bean class for storing a message String.<\/li>\n<\/ul>\n<p style=\"text-align: justify;\"><strong>Developing the UserInfo class\u00a0<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The User class is a Simple Java Bean class. Here it is used for storing information about a user. It has only three properties, name, email and address. The source code for UserInfo is as follows:<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Source code of UserInfoha class<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">package org.epgpathshala.dad.model;<\/p>\n<p style=\"text-align: justify;\">public class UserInfo { private String name; private String email; private String address; public String getName() {<\/p>\n<p style=\"text-align: justify;\">return this.name;<\/p>\n<p style=\"text-align: justify;\">}<\/p>\n<p style=\"text-align: justify;\">public void setName(String n) {<\/p>\n<p style=\"text-align: justify;\">this.name = n;<\/p>\n<p style=\"text-align: justify;\">}<\/p>\n<p style=\"text-align: justify;\">public String getEmail() { return this.email;<\/p>\n<p style=\"text-align: justify;\">}<\/p>\n<p style=\"text-align: justify;\">public void setEmail(String e) {<\/p>\n<p style=\"text-align: justify;\">this.email = e;<\/p>\n<p style=\"text-align: justify;\">}<\/p>\n<p style=\"text-align: justify;\">public String getAddress() { return this.address;<\/p>\n<p style=\"text-align: justify;\">}<\/p>\n<p style=\"text-align: justify;\">public void setAddress(String a) {<\/p>\n<p style=\"text-align: justify;\">this.address = a;<\/p>\n<p style=\"text-align: justify;\">}<\/p>\n<p style=\"text-align: justify;\">}<\/p>\n<p>&nbsp;<\/p>\n<p class=\"hanging-indent\" style=\"text-align: justify;\"><strong style=\"text-align: initial; font-size: 1em;\">Developing the Authenticator class\u00a0<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">The Authenticator class is a simple class, it used for authenticating a user. It has a method called authenticate which takes loginid and password and returns a boolean value. In this demo a simple Authenticator has been developed, which authenticates for a fixed loginid and password. It also has a method for getting the UserInfo object for a given loginid. The code for Authenticator class is as follows:<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">Source for Authenticator class<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">package org.epgpathshala.dad.model;<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">public class Authenticator {<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">public boolean authenticate(String lid, String pswd) {<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">return (lid.equals(&#8220;guest&#8221;)) &amp;&amp; (pswd.equals(&#8220;guest&#8221;));<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">}<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">public UserInfo getUserInfo(String lid) { if (!lid.equals(&#8220;guest&#8221;)) {<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">return null;<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">}<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">UserInfo info = new UserInfo();<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">info.setName(&#8220;Guest&#8221;); info.setEmail(&#8220;<\/span><a style=\"text-align: initial; font-size: 1em;\" href=\"mailto:guest@epgpathsla.org\">guest@epgpathsla.org&#8221;<\/a><span style=\"text-align: initial; font-size: 1em;\">); info.setAddress(&#8220;Ahmedabad&#8221;);<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">return info;<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">}<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p class=\"hanging-indent\" style=\"text-align: justify;\"><strong style=\"font-size: 1em;\">Developing the MessageBean class<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">The MessageBean class is a simple Java Bean class, used for storing a message as a String. It has a single property called message. The code for MessageBean is as follows:<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">Source code of MessageBean class<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">package org.epgpathshala.dad.model;<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">public class MessageBean { private String message = &#8220;&#8221;; public String getMessage() {<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">return this.message;<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">}<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">public void setMessage(String msg) { this.message = msg;<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">}<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">}<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>you can view video on Developing Web Application Using MVC -1<\/strong><\/td>\n<td><a href=\"https:\/\/youtu.be\/d7HUdb2UEWQ\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"hanging-indent\" style=\"text-align: justify;\"><strong style=\"font-size: 1em;\">Suggested Reading:<\/strong><\/p>\n<\/div>\n<ol>\n<li style=\"text-align: justify;\">Expert One-on-One J2EE Development without EJB by Rod Johnson and Juergen Hoeller, Wrox publication<\/li>\n<li style=\"text-align: justify;\">Core Servlets and Java Server Pages Volume 2 by Marty Hall &amp; Larry Brown, Second Edition, Pearson Education.<\/li>\n<li style=\"text-align: justify;\">Inside Servlets by Dustin R Callaway, Pearson Education.<\/li>\n<li style=\"text-align: justify;\">Java Server Programming for Professionals by Ivan Bayross, Sharanam Shah, Cynhthia Bayross and Vaishali Shah Shroff Publishers and Distributros.<\/li>\n<\/ol>\n","protected":false},"author":4,"menu_order":27,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["mr-pravin-jain"],"pb_section_license":""},"chapter-type":[],"contributor":[58],"license":[],"class_list":["post-151","chapter","type-chapter","status-publish","hentry","contributor-mr-pravin-jain"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/pressbooks\/v2\/chapters\/151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/wp\/v2\/users\/4"}],"version-history":[{"count":8,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/pressbooks\/v2\/chapters\/151\/revisions"}],"predecessor-version":[{"id":416,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/pressbooks\/v2\/chapters\/151\/revisions\/416"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/pressbooks\/v2\/chapters\/151\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/wp\/v2\/media?parent=151"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/pressbooks\/v2\/chapter-type?post=151"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/wp\/v2\/contributor?post=151"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/wp\/v2\/license?post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}