postgresql - Implementing a java bean into a jsp servlet -


i trying connect jsp servlets posgress database , using java bean class playing role of middle man. experiencing difficulties making registration form store user information database. appreciate if kindly me out.

thanks lot in advance.

jsp servlet:

<%@page contenttype="text/html" pageencoding="utf-8"%> <head>     <meta http-equiv="content-type" content="text/html; charset=utf-8">     <title>register here</title> </head> <body>     <form method="post" action="registration.jsp">         <center>         <table border="1" width="30%" cellpadding="5">             <thead>                 <tr>                     <th colspan="2">enter information here</th>                 </tr>             </thead>             <tbody>                 <tr>                     <td>first name</td>                     <td><input type="text" name="fname" value="" /></td>                 </tr>                 <tr>                     <td>last name</td>                     <td><input type="text" name="lname" value="" /></td>                 </tr>                 <tr>                     <td>email</td>                     <td><input type="text" name="email" value="" /></td>                 </tr>                 <tr>                     <td>user name</td>                     <td><input type="text" name="uname" value="" /></td>                 </tr>                 <tr>                     <td>password</td>                     <td><input type="password" name="pass" value="" /></td>                 </tr>                 <tr>                     <td>current country</td>                     <td><input type="text" name="country" value="" /></td>                 </tr>                 <tr>                    <td>current city</td>                    <td><input type="text" name="city" value="" /></td>                 </tr>                    <tr>                     <td><input type="submit" value="submit" /></td>                     <td><input type="reset" value="reset" /></td>                 </tr>                 <tr>                     <td colspan="2">already have account? <a href="index.jsp">login here</a></td>                 </tr>             </tbody>         </table>         </center>     </form> </body> 

the java bean use :

public class userbean {      private int id;     private string username;     private string password;     private string email;     private string firstname;     private string lastname;     private string enddate;     private boolean validated;      public userbean() {         // empty constructor     }      public int getid() {         return id;     }      public string getusername() {         return username;     }      public string getpassword() {         return password;     }      public string getemail() {         return email;     }      public string getfirstname() {         return firstname;     }      public string getlastname() {         return lastname;     }      public string getenddate() {         return enddate;     }      public boolean isvalidated() {         return validated;     }      public void setid(int id) {         this.id = id;     }      public void setusername(string username) {         this.username = username;     }      public void setpassword(string password) {         this.password = password;     }      public void setemail(string email) {         this.email = email;     }      public void setfirstname(string firstname) {         this.firstname = firstname;     }      public void setlastname(string lastname) {         this.lastname = lastname;     }      public void setenddate(string enddate) {         this.enddate = enddate;     }      public void setvalidated(boolean validated) {         this.validated = validated;     } } 

your pojo javabean won't magically populated data. has no connection database , no way or save data.

you need controller fetches data db, creates model objects, , populates them data. controller responsible saving beans

you write it's better use existing orm frameworks jpa2, custom persistence provider api hibernate, or mybatis. if want, can hand-roll controller direct jdbc calls, injecting connection environment, tends produce lot of boilerplate code little benefit things spring jdbc smooth things over.

some ides, netbeans , eclipse, can auto-generate models , controllers you, though i've never been happy results (particularly failure use parent-class , generic methods , lack of sort of useful error handling).


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -