Total members 10259 | Gratitudes |It is currently Mon May 21, 2012 4:00 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Topic
 Topic subject: Guest Book Application Using Servlets
PostPosted: Fri Oct 17, 2008 1:20 am 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2277
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

* Project Name:   Guest Book Application Using Servlets
* Programmer:   Satish.K
* Type:   Algorithms
* Technology:  Java
* IDE:   Any
Code:
// guestbk.java //

import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class guestbk extends httpservlet
{
   Connection con;
   public void doPost(HttpServletRequest req,HttpServletResponse res)
throws
IOException,ServletException
   {
      PrintWriter out=new PrintWriter(res.getOutputStream());
      int ctr=0;
      res.setContentType("text/html");
   try
   {
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         con=DriverManager.getConnection("jdbc:odbc:booksrc","","");
         Statement stmt=con.createStatement();
         ResultSet rs=stmt.executeQuery("select * from gbook");
         out.println("<Html>");
      out.println("<Head>");
         out.println("<Title>GuestBook</Title>");
         out.println("</Head>");
         out.println("<Table border=1 align=center >");
         out.println("<H4><B><center>GUEST BOOK DETAILS
</center></B></H4><BR>");
         out.println("<TR><TD><b>E-Mail
Address</b></TD><TD><b>Comment</b></TD></TR>");
      while(rs.next())
      {
          ctr++;
          String email=rs.getString("emailid");
          String cmt=rs.getString("comment");
          out.println("<TR><TD>"+email+"</TD><TD>"+cmt+"</TD></TR>");
   }
          out.println("</Table>");
   if(ctr==0)
         out.println("<BR>No Records Found<BR>");
   stmt.close();
       con.close();
     }
         catch(SQLException SQLExcep)
      {
          System.out.println("error");
      }
         catch(ClassNotFoundException CNFE)
      {
          System.out.println("error");
      }
         out.println("</Html>");
         out.close();
     }
}
Code:
// submit.java //
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class submit extends HttpServlet
{
   Connection con;
   public void doPost(HttpServletRequest req,HttpServletResponse res)
throws
IOException,ServletException
{
   String str1,str2;
   str1=req.getParameter("emailid");
   str2=req.getParameter("comment");
   System.out.println(str1);
   System.out.println(str2);
   res.setContentType("text/html");
   PrintWriter out=res.getWriter();
   out.println("<html><h2>Guest Book is Successfully
Updated</h2></html>");
   try
     {
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      con=DriverManager.getConnection("jdbc:odbc:booksrc","","");
      Statement stmt=con.createStatement();
      ResultSet rs;
      int i= stmt.executeUpdate("insert into gbook
values('"+str1+"','"+str2+"')");
        if(i==1)
      {
         System.out.println("ok");
      }
      stmt.close();
      con.close();
      }
         catch(SQLException SQLExcep)
     {
              System.out.println("error");
      }
         catch(ClassNotFoundException CNFE)
      {
          System.out.println("error");
      }}
}

//guestbk.htm//
<Html>
<Head>
<Title>GUEST BOOK</Title>
</Head>
<Body>
<P>
<Center>
<Form Action= "http:\localhost:8080servletguestbk" Method= "POST">
<Input Type="Submit" Value="VIEW THE GUEST BOOK">
</Form>
<BR>
<Form action= "http:\localhost:8080servletsubmit" method= "Post">
ENTER YOUR EMAIL ADDRESS<Br>
<Input Type="text" Name="emailid" Size="40"><BR>
COMMENTS ARE ALWAYS WELCOME<BR>
<TextArea Name="comment" Rows="8" Cols="65"></TextArea>
</Center>
<P>
<P>
<BR>
<P>
<Center>
<Input Type="Submit" Value="Submit">
</Form>
<Input Type="Reset" Value="Reset">
</Center>
<BR>
</Body>
</Html>

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  


 Similar topics
 Application of Cell Phone Jammer
 video chat application in java
 Ajax Source code to Suggest application with JSP Server side
 I need chat application using php
 PHP Phone Book
 I download the phone book coding from your site
 creating application
 want to develop an application of my own
 Application for the post of Network Admin.
 how to develop a mobile application for nokia help of java

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Topic | Next Topic 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team