delete and edit options in struts

delete and edit options in struts

Hi, I am doing an web application using struts, jsp, tomcat server, oracle as a database in netbeans IDE 7.1.2, I have a developed a code for item deletion and updation, it is not showing any errors but the edit and delete operations were not working, so please modify my code given below. please and urgent.

DBtable:

create table iteminsert(
sno number(10),
code varchar(15) not null,
type varchar(25) not null,
quantity number(10) not null,
mrp number(10,2) not null,
pcost number (10,2) not null,
vat number (10) not null,
tcost number(10,2) not null);

commit;

CREATE SEQUENCE seq
     INCREMENT BY 1
     START WITH 1
     MAXVALUE   99999
     NOCACHE
     NOCYCLE;

commit;


**itemupdate.jsp**

<%-- 
    Document   : itemupdate
    Created on : Sep 15, 2012, 3:50:19 PM
    Author     : admin
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>

<%! String code=null; 
%> 
    <style type="text/css">
    body { font-family: Helvetica Neue, Arial, Helvetica, Geneva, sans-serif;  line-height: 1.0em;  font-size: 15px;  
            background: url(images/bg1.jpg) repeat;  margin: 0 auto; }
    </style>



    <table width="1000" cellspacing="0" border=0 align="center">
        <tr><td>
    <jsp:include page="menu.jsp"></jsp:include>
        </td></tr>
    <tr><td>
        <br>
        <br>
        <br>
    <form name="update" method="get">            
    <table width="1000" cellspacing="0" border=1 align="center">
    <tr>
        <td align="middle" width="60"><b>Select</b></td>
        <td align=middle width="120"><b>Item Code</b></td>
        <td align=middle width="250"><b>Item Type</b></td>
        <td align=middle width="120"><b>Quantity</b></td>
        <td align=middle width="180"><b>M.R.P</b></td>
        <td align=middle width="180"><b>Purchase Cost</b></td>
        <td align=middle width="120"><b>VAT on item</b></td>
        <td align=middle width="200"><b>Net Cost</b></td>
    </tr>

     <%
     List list=(List)request.getAttribute("updateprod");
     if(list!=null)
        {
         Iterator iter=list.iterator();
         while(iter.hasNext())
          {
         com.dao.InsertBean ib =(com.dao.InsertBean)iter.next();
         code=ib.getCode();
          %>
        <tr>
            <td align=middle width="60"><input type="checkbox" name="pdeleteitem" value="<%=ib.getCode()%>"</td>
            <td align=middle width="120"><a href="javascript:editProduct('<%=code%>')"><%=code%></a></td>
            <td align=middle width="250"><%=ib.getType()%></td>
            <td align=middle width="120"><%=ib.getQuantity()%></td>
            <td align=middle width="180"><%=ib.getMrp()%></td>
            <td align=middle width="180"><%=ib.getPcost()%></td>
            <td align=middle width="120"><%=ib.getVat()%></td>
            <td align=middle width="200"><%=ib.getTcost()%></td>
        </tr>
        <%
         }
        }
     %>

    </table>
     <table width="1000" cellspacing="0" align="center">
     <tr><td width="500"></td><td><input type="button" value="Delete" name="delete" onclick="deleteProduct()" align="right"></td>
     </tr>
     </table>
    </form>
    </td></tr>
    </table>

     <script type="text/javascript">
        function editProduct(code)
        {
            document.update.action="getproductforupdate.do?code="+code;
            document.update.submit();
        }
     </script>
     <script type="text/javascript">
        function deleteProduct()
        {
            document.update.action="deleteproduct.do";
            document.update.submit();  
        }
    </script>

**InsertDAO.java** 

package com.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class InsertDAO 
{
    Connection con=null;
    PreparedStatement psmt=null;
    PreparedStatement psmt1=null;
    public void setConnection()
    {
        con=DataBaseBean.getConnection();
    }
    public void closeConnection()
    {
        DataBaseBean.closeConnection();
    }
 public List updateProd()
    {
          List arrayList=new ArrayList(); 
        try
        {
            psmt=con.prepareStatement("select * from iteminsert");

            ResultSet rs=psmt.executeQuery();


            while(rs.next())
            {
                InsertBean ib = new InsertBean();
                ib.setCode(rs.getString("code"));
                ib.setType(rs.getString("type"));
                ib.setQuantity(rs.getInt("quantity"));
                ib.setMrp(rs.getFloat("mrp"));
                ib.setPcost(rs.getFloat("pcost"));
                ib.setVat(rs.getInt("vat"));
                ib.setTcost(rs.getFloat("tcost"));

                arrayList.add(ib);
            }
            return arrayList;
        }
        catch(Exception e)
        {
            System.out.println(e);
            return arrayList;
        }
        finally
        {
            try
            {
                psmt.close();
            }
            catch (Exception e)
            {
                System.out.println(e);
            }
        }

    }
}  

**ProdEdit.java**

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action;

import com.dao.InsertBean;
import com.dao.InsertDAO;
import formbeans.InsertForm;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.servlet.ServletException;
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;

/**
 *
 * @author admin
 */
public class ProductEdit extends Action 
{
    public ProductEdit()
    {
    super();  
    }
    /*
     * forward name="success" path=""
     */
    Connection con=null;
    PreparedStatement psmt=null;
    //PreparedStatement psmt1=null;
    public String result;

@Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
    //<editor-fold defaultstate="collapsed" desc="comment">
    HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException
        //</editor-fold>
    {
       InsertForm fr = (InsertForm) form;
       InsertBean ib = new InsertBean();
       InsertDAO idao=new InsertDAO();

        idao.setConnection();
        int i=0;
        int vat=ib.getVat();
        float pcost=ib.getMrp()*ib.getQuantity();
        float tcost=pcost+(pcost*vat)/100;   

        try
        {
            psmt=con.prepareStatement("update iteminsert set type=?,quantity=?,mrp=?,pcost=?,vat=?,tcost=? where code='"+ib.getCode()+"'");
            //psmt.setString(1,ib.getCode());
            psmt.setString(2,ib.getType());
            psmt.setInt(3,ib.getQuantity()); 
            psmt.setFloat(4,ib.getMrp());
            psmt.setFloat(5,pcost);
            psmt.setInt(6,vat);
            psmt.setFloat(7,tcost);
            psmt.setInt(8,ib.getCount());

            i=psmt.executeUpdate();
            result="success";
        }
        catch(Exception e)
        {
            System.out.println("\n Exception : "+e+"\n");

             //result="success";
        }
        finally
        {
            try
            {
                psmt.close();
            }
            catch (Exception e)
            {
                System.out.println(e);
            }
        }

        //int res=idao.editItems(ib);
        if(i>0)
        {
             result="success";

        }
        else
        {
             result="failure";
        }


        idao.closeConnection();
        return  mapping.findForward(result);
       }


}

**ProductDeleteAction.java**

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action;


import com.dao.InsertDAO;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.servlet.ServletException;
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;

/**
 *
 * @author admin
 */
public class ProductDeleteAction extends Action 
{
    public ProductDeleteAction()
    {
    super();  
    }
    /*
     * forward name="success" path=""
     */
    Connection con=null;
    PreparedStatement psmt=null;
    //PreparedStatement psmt1=null;
    public String result;

@Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
    //<editor-fold defaultstate="collapsed" desc="comment">
    HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException
        //</editor-fold>
    {
    try{

        InsertDAO idao=new InsertDAO();
        int a=0;
        idao.setConnection();
        String dele[]=request.getParameterValues("pdeleteitem");
        String query1="delete from iteminsert where code=(?)";
        //String query2="delete from pitems where code=?";
        for(int i=0;i<dele.length;i++)
            {
            psmt=con.prepareStatement(query1);
            psmt.setString(1,dele[i]);
            a= psmt.executeUpdate();
            }
        if(a==1)
        {
            result="success";
        }
        else
        {  
            result="failure";
        } 
        idao.closeConnection();     
        }
    catch(Exception e)
        {
         System.out.println(e);   
        }
    return mapping.findForward("result");
       }

}

**producteditform.jsp**   

<%-- 
    Document   : producteditform
    Created on : Sep 15, 2012, 5:09:41 PM
    Author     : admin
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@ page import="java.util.*"%>
<html locale="true">
    <head>
    <style type="text/css">
    body { font-family: Helvetica Neue, Arial, Helvetica, Geneva, sans-serif;  line-height: 1.0em;  font-size: 15px;  
            background: url(images/bg1.jpg) repeat;  margin: 0 auto; }
    </style>
    </head>
    <body>
    <form action="getprodedit.do" method="get">
        <table cellpadding="0" cellspacing="0" border="0" align="center" width="600">

        <tr><td width="120"></td><td>Item Code:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="code" value="" property="hidden"></td></tr> 
        <tr><td><br></td></tr>
        <tr><td width="120"></td><td>Item Type:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="type" value="" ></td></tr>
        <tr><td><br></td></tr>
        <tr><td width="120"></td><td>Quantity:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="quantity" value="" ></td></tr>
        <tr><td><br></td></tr>
        <tr><td width="120"></td><td>&nbsp;&nbsp;M.R.P:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="mrp" value="" ></td></tr>
        <tr><td><br></td></tr>
        <tr><td width="120"></td><td>&nbsp;&nbsp;VAT:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="vat" value=""></td></tr>
        <tr><td><br></td></tr>        
        <tr><td width="120"></td><td width="300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <button align="center">Submit</button></td></tr>
        </table>
    </form>
    </body>
</html>

**GetProductAction.java**

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action;

import com.dao.InsertDAO;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author admin
 */
public class GetProductAction extends Action  
{
   @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,

            HttpServletRequest request, HttpServletResponse response) 
    {
        String result="failure";
        HttpSession ses = request.getSession();

        InsertDAO idao=new InsertDAO();
        idao.setConnection();

        List arrayList=new ArrayList();
        arrayList=idao.updateProd();
        result="success";
        request.setAttribute("updateprod",arrayList);
        idao.closeConnection();
        return  mapping.findForward(result);
    }
}

**struts-config.xml**

 <!-- Update Stock items -->
        <action path="/updateprod" scope="session" type="action.GetProductAction">
        <forward name="success" path="/itemupdate.jsp" />
        <forward name="failure" path="/error.jsp" />
        </action>
     <!-- end of Update Stock items -->  

     <!-- get items to Edit -->
        <action path="/getproductforupdate" scope="session" type="action.GetProductAction">
        <forward name="success" path="/producteditform.jsp" />
        <forward name="failure" path="/error.jsp" />
        </action>
     <!-- end of get items to Edit --> 

     <!-- Edit items -->
        <action path="/getprodedit" scope="session" type="action.ProductEdit">
        <forward name="success" path="/updateprod.do" />
        <forward name="failure" path="/error.jsp" />
        </action>
     <!-- end of Edit items --> 

     <!-- Delete Items -->
        <action path="/deleteproduct" scope="session" type="action.ProductDeleteAction">
        <forward name="success" path="/updateprod.do" />
        <forward name="failure" path="/error.jsp" />
        </action>
     <!-- end of Delete items --> 
View Answers









Related Tutorials/Questions & Answers:
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application using struts, jsp, tomcat server, oracle as a database in netbeans IDE 7.1.2, I... errors but the edit and delete operations were not working, so please modify my
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application using struts, jsp, tomcat server, oracle as a database in netbeans IDE 7.1.2, I... errors but the edit and delete operations were not working, so please modify my
Advertisements
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application using struts, jsp, tomcat server, oracle as a database in netbeans IDE 7.1.2, I... errors but the edit and delete operations were not working, so please modify my
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application using struts, jsp, tomcat server, oracle as a database in netbeans IDE 7.1.2, I... errors but the edit and delete operations were not working, so please modify my
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application using struts, jsp, tomcat server, oracle as a database in netbeans IDE 7.1.2, I... errors but the edit and delete operations were not working, so please modify my
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application using struts, jsp, tomcat server, oracle as a database in netbeans IDE 7.1.2, I... errors but the edit and delete operations were not working, so please modify my
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application using struts, jsp, tomcat server, oracle as a database in netbeans IDE 7.1.2, I... errors but the edit and delete operations were not working, so please modify my
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application using struts, jsp, tomcat server, oracle as a database in netbeans IDE 7.1.2, I... errors but the edit and delete operations were not working, so please modify my
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application using struts, jsp, tomcat server, oracle as a database in netbeans IDE 7.1.2, I... errors but the edit and delete operations were not working, so please modify my
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application using struts, jsp, tomcat server, oracle as a database in netbeans IDE 7.1.2, I... errors but the edit and delete operations were not working, so please modify my
delete and edit options in struts
delete and edit options in struts   Hi, I am doing an web application... errors but the edit and delete operations were not working, so please modify my...;/action> <!-- end of Edit items --> <!-- Delete Items
data grid with edit and delete options at each row.
data grid with edit and delete options at each row.  i want to display the table data in the format of data grid with edit and delete options at each row. i need it very urgently. advance thanks
create,edit and delete in JSP using struts and SQL server2005 as database in jdeveloper?
create,edit and delete in JSP using struts and SQL server2005 as database... to create,edit and delete tasks: taskid, taskname, date, project in JSP and struts and SQL server2005 in JDEVELOPER. I have not worked on struts yet.How should i
create,edit and delete in JSP using struts and SQL server2005 as database in jdeveloper?
create,edit and delete in JSP using struts and SQL server2005 as database... to create,edit and delete tasks: taskid, taskname, date, project in JSP and struts and SQL server2005 in JDEVELOPER. I have not worked on struts yet.How should i
insert , edit , and delete button in one jsp page
insert , edit , and delete button in one jsp page  hello I want to ask about the way of creating a jsp page contains insert , edit , and delete buttons and manipulate data in database directly. any help please or hints
Delete and edit data in xml file using JSP
Delete and edit data in xml file using JSP   I want to know how to delete and edit data from an XML file by use of JSP. I have XML file having tasks... in the xml file,I want to delete and edit some tasks using task id then how can i do
Add Edit And Delete Employee Information
Add Edit and Delete Employee Information Using Swing  ..., edit and delete the Employee's information from the database using java swing... information into the database. The second tab will edit the Employee's information
in order to create jsp and servlet code to add,delete,edit,list of persons in eclipsejavaee
in order to create jsp and servlet code to add,delete,edit,list of persons in eclipsejavaee  in order to create jsp and servlet code what all files we need to create in eclipse --dynamic web project
please tell anybody how can i set a value in hiperlink for edit n delete link
please tell anybody how can i set a value in hiperlink for edit n delete link  <logic:present name="allRecords"> <logic:notEmpty name="allRecords"> <logic:iterate id="user" name
Update delete perticular row from brower on link - Struts
Update delete perticular row from brower on link   how can update and delete perticular row from List of employee in brower format are ramesh patel 34334 mumbai update delete smita kadam 45454 new york update
delete
;td><input type="button" name="edit" value="Delete" style="background-color...delete  how delete only one row in the database using jsp.database..."); Statement st = conn.createStatement(); st.executeUpdate("DELETE FROM employee
DELETE
DELETE   I AM DOING IT IN MYSQL. DELETE FROM EMP WHERE SAL>(SELECT SAL FROM EMP WHERE ENAME='MILLAR') AND ENAME='ALLEN'; THIS IS GIVING THE FOLLOWING ERROR Error Code : 1093 You can't specify target table 'EMP
Struts Console
visually edit Struts, Tiles and Validator configuration files. The Struts Console... Struts Console         The Struts Console is a FREE standalone Java Swing
Struts 2
will have two buttons like add and edit and a data grid will have the radio button and user needs to select the rows to edit or delete. Please help me the code...Struts 2   I am just new to struts 2 and need to do the task. I have
edit data
edit data  sir i want to do edit a particular customers information after he logs in, i am also using sessions. thank you
Edit Distance
Edit Distance  I want java programming ask from user input two string and the program find the edit distance between two strings and find table and optimal solution using GUI
Delete and add row from Table View iPhone
Delete and add row from Table View iPhone In this tutorial will learn how to delete and also how to add row into the table view iPhone, with the help of edit button on navigation bar. When we press Edit button it will show you ADD
Edit the record.
Edit the record.  sir, I have a table consist of huge data.I have displayed that data.side of them there is an edit button which will edit that particular record.after editing the data i want to edit another row which is next
Struts
Struts   How to retrive data from database by using Struts
STRUTS
STRUTS  MAIN DIFFERENCES BETWEEN STRUTS 1 AND STRUTS 2
STRUTS
STRUTS  MAIN DIFFERENCES BETWEEN STRUTS 1 AND STRUTS 2
Struts
Struts  what is SwitchAction in struts
Struts
Struts  how to learn struts
STRUTS
STRUTS   Request context in struts? SendRedirect () and forward how to configure in struts-config.xml
Delete Account
Delete Account  How to delete account
struts
struts  in industry, struts 1 and struts 2. which is the best? which is useful as a professuional   Have a look at the following link: Struts Tutorials
struts
struts  what are the 4 methods of struts framework
struts
struts shopping cart project in struts with oracle database connection  shopping cart project in struts with oracle database connection   Have a look at the following link: Struts Shopping Cart using MySQL
Struts
Struts  Tell me good struts manual
ModuleNotFoundError: No module named 'options'
ModuleNotFoundError: No module named 'options'  Hi, My Python... 'options' How to remove the ModuleNotFoundError: No module named 'options... to install padas library. You can install options python with following command
Struts
Struts   When Submit a Form and while submit is working ,press the Refresh , what will happen in Struts
struts
struts  Hi what is struts flow of 1.2 version struts? i have struts applicatin then from jsp page how struts application flows Thanks Kalins Naik   Please visit the following link: Struts Tutorial
struts
struts   how to write Dao to select data from the database
struts
struts  why doc type is not manditory in struts configuration file
struts
struts  why doc type is not manditory in struts configuration file
struts
struts  why doc type is not manditory in struts configuration file
struts
struts  why doc type is not manditory in struts configuration file
Struts
Struts  Hi i am new to struts. I don't know how to create struts please in eclipse help me
struts
struts   Hi how struts flows from jsp page to databae and also using validation ? Thanks Kalins Naik
Struts
Setter methods of form bean class in Struts applications  who calls the setter methods of form bean class in struts applications

Ads