 Define a table in Database shanu database in ms access
PREPARE A TABLE COFFEES
FIELDS
cof_name text (primary key)
sup_id number
price number
sales number
total number


Prepare a user dsn named shanu Now write fetch.jsp as defined below

<%@page import="java.sql.*"%>
<%! public Connection con = null; %>
<html>
<head>
<script Language="JavaScript">
function reloading()
{
document.forms[0].action="login.do"
document.forms[0].submit();
}
function edit_click(str1,str2,str3,str4,str5)
{
document.getElementById('status_now').value="editi ng";
document.getElementById('coffee_name').value = str1;
document.getElementById('supplier_id').value = str2;
document.getElementById('price').value = str3;
document.getElementById('sales').value = str4;
document.getElementById('total').value = str5;
}




function del_click(str1)
{
alert(str1);
document.forms[0].action="login.do?status=deleting&cof_name="+str1;
document.forms[0].submit();
}

function submit_click()
{
if (document.getElementById('status_now').value=="ins erting")
{
alert(document.getElementById('status_now').value) ;
document.forms[0].action="login.do?status=inserting";
document.forms[0].submit();
}
if (document.getElementById('status_now').value=="edi ting")
{
alert(document.getElementById('status_now').value) ;
document.forms[0].action="login.do?status=editing";
document.forms[0].submit();
}
if (document.getElementById('status_now').value=="del eting")
{
alert(document.getElementById('status_now').value) ;
document.forms[0].action="login.do?status=deleting";
document.forms[0].submit();
}

}
</script>
</head>
<body >

<form action="" method="post" name="form1" >
<%
try{
String ss =null;
String ss1=null;
String ss2=null;
String ss3=null;
String ss4=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:shanu";
con = DriverManager.getConnection(url);
Statement st=con.createStatement();
ResultSet rs= st.executeQuery("select * from coffees");
%>

<table cellpadding="1" cellspacing="1" border="1" bordercolor = "red" align="center" width="500">
<tr>
<td colspan="2" align="center"> <b>Entry Screen</b> </td>
</tr>
<tr>
<td> Coffee Name </td>
<td>
<input type="text" id="coffee_name" name="coffee_name" />
</td>
</tr>
<tr>
<td> Supplier Id </td>
<td>
<input type="text" id="supplier_id" name="supplier_id" /> </td>
</tr>
<tr>
<td> Price </td>
<td>
<input type="text" id="price" name="price" /> </td>
</tr>
<tr>
<td> Sales </td>
<td>
<input type="text" id="sales" name="sales" /> </td>
</tr>
<tr>
<td> Total </td>
<td>
<input type="text" id="total" name="total" /> </td>
</tr>
<tr>
<td colspan="2" align="center"><input type="button" id="save" name="save" value="Submit" onClick="submit_click()"/>
<input type="button" id="reset" name="reset" value="Reset" /> </td>
</tr>
</table>
<table cellpadding="1" cellspacing="1" border="1" bordercolor = "red" align="center" width="500">
<tr>
<td>
<b>Coffee Name</b>
</td>
<td>
<b>Supplier Id</b>
</td>
<td>
<b>Price</b>
</td>
<td>
<b>Sales</b>
</td>
<td>
<b>Total</b>
</td>
<td>
<b>Edit</b>
</td>
<td>
<b>Delete</b>
</td>
</tr>
<%
while(rs.next())
{
%>
<tr>
<td>
<%
ss = rs.getString(1);
out.println(ss.toString());
%>
</td>
<td>
<%
ss1 =""+rs.getInt(2);
out.print(ss1);
%>
</td>
<td>
<%
ss2 =""+rs.getInt(3);
out.print(ss2);
%>
</td>
<td>
<%

ss3 =""+rs.getInt(4);
out.print(ss3);
%>
</td>
<td>
<%
ss4 =""+rs.getInt(5);
out.print(ss4);
%>
</td>
<td><a href="#" onClick= "edit_click('<%=ss.toString()%>','<%=ss1.toString( )%>','<%=ss2.toString()%>','<%=ss3.toString()%>',' <%=ss4.toString()%>')")>edit</a></td>
<td><a href="#" onClick= "del_click('<%=ss.toString()%>')">delete</a></td>
</tr>
<%
}
%>
</table>
<%

con.close();
}
catch(Exception e){}
%>
<input type="hidden" id="status_now" name="status_now" value="inserting">

</form>

</body>
</html>
fetch.jsp ends here
failure.jsp begins here
<html>
<head></head>
<body>
<h1> Failed</h1>
</body>
</html>
failure.jsp ends here

Now define a package mypackage under WEB-INF
HERE CREATE AN ACTION CLASS AND AN ACTION FORM DEFINED BELOW

ACTION CLASS :- userAction.java
package mypackage;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class userAction extends Action
{

public ActionForward execute(ActionMapping mapping , ActionForm form,HttpServletRequest request, HttpServletResponse response) throws Exception
{
UserForm formBean =(UserForm)form;
String coffee_name = formBean.getCoffee_name();
Integer supplier_id = formBean.getSupplier_id();
Integer price = formBean.getPrice();
Integer sales = formBean.getSales();
Integer total = formBean.getTotal();
String status = request.getParameter("status");
String del_cofee_name= request.getParameter("cof_name");
String retMap=null;
user_process up = new user_process();

System.out.print("1st cofe name:::"+coffee_name);

if (status.equals("inserting"))
{
System.out.print("2nd cofe name:::"+coffee_name);
if ((coffee_name == null) ||
(supplier_id == null) ||
(price ==null) ||
(sales==null) ||
(total==null))
{
System.out.println("failure");
retMap= "FAILURE";
}
else
{
System.out.print("3rd cofe name:::"+coffee_name);
up.insert(coffee_name, supplier_id, price, sales, total);

retMap= "SUCCESS";
}
return mapping.findForward(retMap);
}

if (status.equals("editing"))
{
if ((coffee_name == null)||(supplier_id == null)||(price ==null)||
(sales==null) ||
(total==null))
{
System.out.println("failure");
retMap= "FAILURE";
}
else
{
System.out.print("3rd cofe name:::"+coffee_name);
up.update(coffee_name, supplier_id, price, sales, total);
retMap= "SUCCESS";
}
return mapping.findForward(retMap);
}

if (status.equals("deleting"))
{
if ((del_cofee_name == null))
{ // email lacks '@'
System.out.println("failure");
retMap= "FAILURE";
}
else
{
up.delete(del_cofee_name);
retMap= "SUCCESS";
}
return mapping.findForward(retMap);
}
return mapping.findForward(retMap);
}
}
action class ends here

Action Form :- UserForm.java
package mypackage;

public class UserForm extends org.apache.struts.action.ActionForm {
private String coffee_name;
private Integer supplier_id;
private Integer price;
private Integer sales;
private Integer total;
public String getCoffee_name() {
return coffee_name;
}
public void setCoffee_name(String coffee_name) {
this.coffee_name = coffee_name;
}
public Integer getSupplier_id() {
return supplier_id;
}
public void setSupplier_id(Integer supplier_id) {
this.supplier_id = supplier_id;
}
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
this.price = price;
}
public Integer getSales() {
return sales;
}
public void setSales(Integer sales) {
this.sales = sales;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}


}
Action Form Ends Here

struts-config.xml Begins Here
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>

<form-beans>
<form-bean name="userForm" type="mypackage.UserForm" />
<form-bean name="cust_info" type= "mypackage.CustInfo" />
</form-beans>

<global-forwards>
<forward name="logout" path="/index.jsp"/>
</global-forwards>

<action-mappings>
<action path="/login" name="userForm" type="mypackage.userAction" scope="request">
<forward name="SUCCESS" path="/fetch.jsp" />
<forward name="FAILURE" path="/failure.jsp" />
</action>

<action path="/cust_info" name="cust_info" type="mypackage." scope="request">
<forward name="SUCCESS" path="/fetch.jsp" />
<forward name="FAILURE" path="/failure.jsp" />
</action>



</action-mappings>

</struts-config>

struts-config.xml ends here



web.xml starts here



<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<session-config>
<session-timeout>30</session-timeout>
</session-config>

<welcome-file-list>
<welcome-file>fetch.jsp</welcome-file>
</welcome-file-list>
</web-app>

web.xml ends here
user_process.java begins here


package mypackage;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class user_process {
public void insert (String cof_name,Integer sup_id,Integer price,Integer sales,Integer total ) throws Exception
{
Connection con = null;
PreparedStatement pstmt = null;

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:shanu";
con = DriverManager.getConnection(url, "", "");
String query = "insert into coffees(cof_name, sup_id, price,sales,total) values(?, ?, ?, ?, ?)";

pstmt = con.prepareStatement(query); // create a statement
pstmt.setString(1,cof_name);
pstmt.setInt(2, sup_id);
pstmt.setInt(3, price);
pstmt.setInt(4, sales);
pstmt.setInt(5, total);
pstmt.executeUpdate();

} catch (Exception e) {
e.printStackTrace();
} finally {
pstmt.close();
con.close();
}


}


public void delete (String cof_name ) throws Exception
{

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:shanu";
Connection con = DriverManager.getConnection(url, "", "");
PreparedStatement deleteSales = con.prepareStatement(
"DELETE FROM COFFEES WHERE COF_NAME = ? ");
deleteSales.setString(1, cof_name );
deleteSales.executeUpdate();

if(con!=null)con.close();
} catch (Exception e){}


}
public void update (String cof_name,Integer sup_id,Integer price,Integer sales,Integer total ) throws Exception
{

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:shanu";
Connection con = DriverManager.getConnection(url, "", "");
PreparedStatement updateSales = con.prepareStatement(
"UPDATE COFFEES SET sup_id=? , price =?,SALES = ?,total= ? WHERE COF_NAME LIKE ? ");
updateSales.setInt(1, sup_id );
updateSales.setInt(2, price );
updateSales.setInt(3, sales );
updateSales.setInt(4, total );
updateSales.setString(5, cof_name );
updateSales.executeUpdate();

if(con!=null)con.close();
} catch (Exception e){}


}
}

:)