Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Struts delete and edit options in struts

Have Programming Question? Ask it here!
 
 
 


surya lakshmi
delete and edit options in struts
0 Answer(s)      a year and 7 months ago
Posted 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 --> 

Advertisement
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
delete
type="button" name="edit" value="Delete" style="background-color:red;font-weight...delete  how delete only one row in the database using jsp.database... = conn.createStatement(); st.executeUpdate("DELETE FROM employee WHERE empid
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
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
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
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
The options tag
In this section, you will learn about the options tag of Spring form tag library
How to create options in HTML
How to create options in HTML  How to create options in HTML? Please guide me.   Create options in HTML Code <tr> <td width="30" valign="middle">Gender:</td> <td><select
ajax+options is null or not an Object
ajax+options is null or not an Object  HI i have developed a simple ajax application contains two drop down lists and and one search button when i... dispalay me the employee details when i click on search button its saying options
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
Struts Console
visually edit Struts, Tiles and Validator configuration files. The Struts Console... Struts Console         The Struts Console is a FREE standalone Java Swing
Edit image - XML
Edit image  How to edit my Image Document Online?  Just visit http://www.onlinedocumentconversion.com/ and register there, upload and convert your image
how to edit a record in hibernate?
how to edit a record in hibernate?  how to edit a record in hibernate?   Hi Friend, Please visit the following link: Hibernate Tutorials Thanks   Hi Friend, Please visit the following link: Hibernate
Edit cron entry
Edit cron entry   Hi, What is the command to Edit cron entry in linux? Regards Deepak Kumar   Hi, You can use the following command to open cron configuration in vi editor: crontab -e After editing just save
UINavigationBar Edit Button
UINavigationBar Edit Button  UINavigationBar Edit Button Given is the code that adds a edit button item as a nav bar item in your UINavigation Controller. -(void)viewDidLoad; { [super viewDidLoad]; UINavigationBar* navBar
uitableview edit done button
uitableview edit done button  How to add Edit / Done button in UITableView with an action on click?   UITableview Edit done Button To add " Edit / Done button " in UITableView add the given code in UIView Controller
Delete Account
Delete Account  How to delete account
Update / Edit data
Update / Edit data  Hello, i want to create a page to edit or update... consists of that particular id. When the user clicks the particular edit button...="button" name="edit" value="Edit" style="background-color:green;font-weight:bold
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
Java memory options from command line
Java memory options from command line  Hi, How to use java memory options from command line? Thanks   Hi, Here is the example code: java -Xms1056m -Xmx1056m MyProgram Thanks
jsp :how to edit table of data displayed using jsp when clicked on edit button
jsp :how to edit table of data displayed using jsp when clicked on edit button  i have a jsp program which displays data in the form of table ..now i want to delete this information in table when click on delete button and save
edit values of database using jsp
edit values of database using jsp  hi i want a code to edit the row from tye database and display in a page which containd radio buttons and drop down boxes using jsp code
edit values of database using jsp
edit values of database using jsp  hi i want a code to edit the row from tye database and display in a page which containd radio buttons and drop down boxes using jsp code
Ask Questions with Options
Ask Questions with Options using Java In this section, we are going to ask five questions one after the other with four options to test the user. For this, we have stored 5 questions, answers with four options into a list. The list
from a list of options perform a desired action is referred as
from a list of options perform a desired action is referred as  A list of options from which a program user can select anyone in order to perform a desired action is referred as - Menu Index Directory All of these None
To delete post
To delete post  How can I delete my old post answer. I've posted 2 same answers by mistake
Dedicated server options
Dedicated server options In this section we will study about the different dedicated server options available while placing order for dedicated servers... for different purposes. Dedicated server options Single Processor Server If you don't
radio button value on edit action
provided show edit add and delete link for each customer that is searched...Problem 'm facing is on edit action 'm not retrieving radio button value..i have...radio button value on edit action  This is my edit.jsp code...In my
delete jsp
delete jsp  <%@ page language="java" contentType="text/html...; charset=ISO-8859-1"> <title>Delete Student</title> </head>...;/Controller"> <input type="hidden" name="page" value="delete"/> <
edit database using jsp and servlet
edit database using jsp and servlet  I am creating a website using... to edit the information of each house. showAll.jsp shows all the houses and beside that is a link to an edit page. The edit page needs to display all the house
 

 

 

DMCA.com