Three Tier Architecture
//datainsert.java
import java.io.*;
import java.lang.*;
import java.sql.*;
import javax.servlet.*;...
pst.setString(3,pass1);
pst.setString(4,cpass1);
pst.setString(5,phno1);
pst.setString(6,emailid1);
pst.setString(7,gender...
PrintWriter out=res.getWriter();
//out.println("<p> connection established</p>");
String first1=req.getParameter("fname");...
}
rs.close();
con.close();
out.close();
}
catch(Exception e)
{
e.printStackTrace();
}

}
}
dataretrive.html
<html>
<head>
...
var cpassword=document.form.cpass.value;
var c = document.form.phno.value;
var address=document.form.email.value;
var reg ...
alert("Phone no. cannot be left
blank");
document.form.phno.focus();
return false;
}

if(isNaN(c)|| c.indexOf(" ")!=-1)
{
...
<tr><td><STRONG><b><font
color="green">REGISTRATION:</font><b></STRONG></td></tr>
<tr><td><font color="blue">First Name</f...
To Create ms-access database

Click on new link- click blank database--window will open

Enter database name regdb1 save...
Clck on create table in design view

Create number of field names based on number of registrationpage fields
And close sub...
Now table created if u click on regtable1 it will show fields

Close all windows now go start -settings-control panel-c...
Click on datasource

Click on add tab
Select Microsoft Access Driver(*.mdb) click finish
Enter Data Source Name regdsn1 and click select
Select database from my documents select regdb1 and click ok-ok-ok
It will close all windows now driver connection over
...
C:Program Filesapache-tomcat6.0.36webappsROOTWEB-INFsrc>javac
dataretrive.java

Step4: create datainsert.classes and datar...
</web-app>
Step6: Start apache-tomacat server double click on bin

C:Program Filesapache-tomcat6.0.36bin
Step7:after serve...
http://localhost:8080/userregistration.html
http://localhost:8080/dataretrive.html
Three tier application
Three tier application
Three tier application
Upcoming SlideShare
Loading in …5
×

Three tier application

750 views
423 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
750
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
3
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Three tier application

  1. 1. Three Tier Architecture //datainsert.java import java.io.*; import java.lang.*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; public class datainsert extends HttpServlet{ public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Connection connection; try{ String first1=req.getParameter("fname"); String last1=req.getParameter("lname"); String pass1=req.getParameter("pass"); String cpass1=req.getParameter("cpass"); String phno1=req.getParameter("phno"); String emailid1=req.getParameter("email"); String gender1=req.getParameter("gender"); String area1=req.getParameter("area"); String sel1=req.getParameter("sel"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); connection = DriverManager.getConnection("jdbc:odbc:regdsn1"," "," "); PreparedStatement pst = connection.prepareStatement("insert into regtable1 values(?,?,?,?,?,?,?,?,?)"); pst.setString(1,first1); pst.setString(2,last1);
  2. 2. pst.setString(3,pass1); pst.setString(4,cpass1); pst.setString(5,phno1); pst.setString(6,emailid1); pst.setString(7,gender1); pst.setString(8,area1); pst.setString(9,sel1); int i = pst.executeUpdate(); if(i!=0){ pw.println("<br>Record has been inserted"); } else{ pw.println("failed to insert the data"); } } catch (Exception e){ pw.println(e); } } } //dataretrive.java import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; public class dataretrive extends HttpServlet { public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException { /* database connection*/ try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:regdsn1","","");
  3. 3. PrintWriter out=res.getWriter(); //out.println("<p> connection established</p>"); String first1=req.getParameter("fname"); Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery("select * from regtable1 where firstname='"+first1+"'"); if (!rs.next()) { out.println("<html><head><title> Hello</title></head><body> <h1>Incorrect Username and password </h1></body><html>"); } else { out.println("<html><head><title> Hello</title></head>"); out.println("<body><p> <h1>welcome to"+" "+ req.getParameter("fname")+"</h1></p>"); out.println("<table border=2><tr><th>REGISTERDFIELDS</th><th>VALUE</th></tr>"); out.println("<tr><td>FIRST NAME</td><td>"); out.println(rs.getString(1)); out.println("</td></tr><td>LAST NAME</td><td>"); out.println(rs.getString(2)); out.println("</td></tr><td>PASSWORD</td><td>"); out.println(rs.getString(3)); out.println("</td></tr><td>CPASSWORD</td><td>"); out.println(rs.getString(4)); out.println("</td></tr><td>PHONENUMBER</td><td>"); out.println(rs.getString(5)); out.println("</td></tr><td>EMAIL-ID</td><td>"); out.println(rs.getString(6)); out.println("</td></tr><td>GENDER</td><td>"); out.println(rs.getString(7)); out.println("</td></tr><td>ADDRESS</td><td>"); out.println(rs.getString(8)); out.println("</td></tr><td>STATE</td><td>"); out.println(rs.getString(9)); out.println("</td></tr></table>");
  4. 4. } rs.close(); con.close(); out.close(); } catch(Exception e) { e.printStackTrace(); } } } dataretrive.html <html> <head> <title>Login Page</title> </head> <body> <form method="GET" action="/dataretrive"> <p>Enter Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="fname" size="20"></p> <input type="submit" value="Submit" name="B1"></p> </form> </body> </html> userregistration.html <DOCTYPE html> <head> <title>REGISTRATION PAGE</TITLE> <script type="text/javascript"> function validation() { var a = document.form.fname.value; var b = document.form.lname.value; var password=document.form.pass.value;
  5. 5. var cpassword=document.form.cpass.value; var c = document.form.phno.value; var address=document.form.email.value; var reg = /^([A-Za-z0-9_-.])+@([A-Za-z0-9_-.])+.([A-Za-z]{2,4})$/; var gender = document.form.gender.value; if(a=="" || a==null) { alert("Please Enter Your first Name"); document.form.fname.focus(); return false; } if(b=="" || b==null) { alert("Please Enter Your last Name"); document.form.lname.focus(); return false; } if(password=="" || password==null) { alert("Please Enter Your password"); document.form.pass.focus(); return false; } if (password.length < 6) { alert("enter minimum 6 characters"); document.form.pass.focus(); return false; } if(password!=cpassword) { alert("Please Enter Your correct password"); document.form.cpass.focus(); return false; } if (c==null || c=="") {
  6. 6. alert("Phone no. cannot be left blank"); document.form.phno.focus(); return false; } if(isNaN(c)|| c.indexOf(" ")!=-1) { alert("Enter numeric value"); document.form.phno.focus(); return false; } if (c.length < 10) { alert("enter 10 characters"); document.form.phno.focus(); return false; } if(reg.test(address) == false) { alert('Invalid Email Address'); return false; } if ( ( form.gender[0].checked == false ) && ( form.gender[1].checked == false ) ) { alert ( "Please choose your Gender: Male or Female" ); return false; } if (ErrorText= "") { form.submit() } } </script> </head> <body bgcolor="#E6E6FA"> <table> <form name="form" method="POST" action="/datainsert" onsubmit="return validation()">
  7. 7. <tr><td><STRONG><b><font color="green">REGISTRATION:</font><b></STRONG></td></tr> <tr><td><font color="blue">First Name</font><font color="red">*:</font></td> <td><input type="text" name="fname" size=20></td></tr> <tr><td><font color="blue">Last Name</font><font color="red">*:</font></td><td><input type="text" name="lname" size=20></td></tr> <tr><td><font color="blue">Password</font><font color="red">*:</font></td><td> <input type="password" name="pass" size=15></td></tr> <tr><td><font color="blue">Confirm Password</font><font color="red">*:</font></td><td> <input type="password" name="cpass" size=15></td></tr> <tr><td><font color="blue">PhoneNo</font><font color="red">*:</font></td><td> <input type="text" name="phno" size=10></td></tr> <tr><td><font color="blue">Email-id</font><font color="red">*:</font></td><td> <input type="text" name="email" size=10></td></tr> <tr><td><font color="blue">Select Gender</font><font color="red">*:<td></font><input type="radio" name="gender" value="male"><font color="blue">MALE:</font> <input type="radio" name="gender" value="female"><font color="blue">FEMALE:</font></td></tr> <tr><td><font color="blue">Address:</font></td><td><textarea name="area" size=20></textarea></td></tr> <tr><td><font color="blue">Select State:</font></td><td><select name="sel"> <option name="tn">TAMILNADU</option> <option name="ap">ANDHARA PRADESH</option> <option name="kl">KERALA</option> </select> </td></tr> <tr><td><input type="submit" name="sub" value="Submit"></td></tr> </tr> </form></table> </body> </html>
  8. 8. To Create ms-access database Click on new link- click blank database--window will open Enter database name regdb1 save in mydocuments-click on create
  9. 9. Clck on create table in design view Create number of field names based on number of registrationpage fields And close sub window it will ask save -save table name regtable1 Again it will ask primary key yer or no -click no
  10. 10. Now table created if u click on regtable1 it will show fields Close all windows now go start -settings-control panel-click on administrative tools(if suppose not there check performance and maintance)
  11. 11. Click on datasource Click on add tab
  12. 12. Select Microsoft Access Driver(*.mdb) click finish
  13. 13. Enter Data Source Name regdsn1 and click select
  14. 14. Select database from my documents select regdb1 and click ok-ok-ok It will close all windows now driver connection over Step1: Create datainsert .java file and dataretrive.java and save in C:Program Filesapache-tomcat6.0.36webappsROOTWEBINFsrcdatainsert.java C:Program Filesapache-tomcat6.0.36webappsROOTWEBINFsrcdataretrive.java Step2: Create userregistration.html file save in C:Program Filesapachetomcat6.0.36webappsROOTuserregistration.html C:Program Filesapache-tomcat6.0.36webappsROOTdataretrive.html Step3: Compile datainsert.java and dataretrive.java Open command prompt C:Document and Settingsadministrator>cd Copy and paste full path upto src C:cd C:Program Filesapache-tomcat6.0.36webappsROOTWEBINFsrc C:Program Filesapache-tomcat6.0.36webappsROOTWEB-INFsrc>javac datainsert.java
  15. 15. C:Program Filesapache-tomcat6.0.36webappsROOTWEB-INFsrc>javac dataretrive.java Step4: create datainsert.classes and dataretrive.classes file in src (cut and past in classes folder save file in this location C:Program Filesapache-tomcat6.0.36webappsROOTWEB-INFclasses Step5: Create web.xml file with web.xml coding give two files name <web-apps> <web-app> <servlet> <servlet-name>datainsert</servlet-name> <servlet-class>datainsert</servlet-class> </servlet> <servlet-mapping> <servlet-name>datainsert</servlet-name> <url-pattern>/datainsert</url-pattern> </servlet-mapping> <servlet> <servlet-name>dataretrive</servlet-name> <servlet-class>dataretrive</servlet-class> </servlet> <servlet-mapping> <servlet-name>dataretrive</servlet-name> <url-pattern>/dataretrive</url-pattern> </servlet-mapping>
  16. 16. </web-app> Step6: Start apache-tomacat server double click on bin C:Program Filesapache-tomcat6.0.36bin Step7:after server startup open browser type url
  17. 17. http://localhost:8080/userregistration.html
  18. 18. http://localhost:8080/dataretrive.html

×