Home Answers Viewqa Struts delete and edit options in struts

 
 


surya lakshmi
delete and edit options in struts
0 Answer(s)      8 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"%> <%@page import="java.util.Iterator"%> <%@page import="java.util.List"%>

<%! String code=null; %>

<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>

 <%
 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>

 <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, // HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException // { 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, // HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException // { 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"%> <%@ page import="java.util.*"%>

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

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

 <!-- 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 Pages:
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 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
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
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
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
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
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
redirect with tiles - Struts
Image Price Edit Delete edit... in struts 2. And i want redirect to other definition tag by url tag. Please help me
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
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 - Struts
Struts  hi can anyone tell me how can i implement session tracking in struts? please it,s urgent...........  session tracking? you mean... that session and delete its value like this... session.removeAttribute
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 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
Based on struts Upload - Struts
Based on struts Upload  hi, i can upload the file in struts but i want the example how to delete uploaded file.Can you please give the code
STRUTS INTERNATIONALIZATION
STRUTS INTERNATIONALIZATION -------------------------------- by Farihah... to implement Internationalization (abbreviated as I18N) in Struts... or country needs to be supported. Struts provides various locale sensitive JSP tags
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 Code - Struts
using struts . I am placing two links Update and Delete beside each record . Now I...Struts Code  Hi I executed "select * from example" query... Delete But it is not appending.. Can any one help me. Thanks in Advance
Struts Example - Struts
Struts Example  Hi Deepak My name is dendi i want some good example in struts framework with sample code , hw to add and delete insert and update data into database by using sql, nw i am learning java struts u can help me
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
Java App - Add, Delete, Reorder elements of the buttons
Java App - Add, Delete, Reorder elements of the buttons  Hello... elements as he needs. He can edit element infomrations at any time by clicking on "Element N" Button. He can too delete an element or change the order
Hi... - Struts
Hi...  Hi, If i am using hibernet with struts then require... persistence services such as create, read, update and delete (CRUD). For read more information,tutorials and examples on Struts with Hibernate visit
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
Activity display dynamically depend on the locale on Struts
to display activities dynamically which can be increase or decrease on struts 2... can be expend or collapse (add or delete) activity at run time. I have two... direction or any suggestion.. Thanks   i am doing some edit on my
struts with hibernate - Hibernate
struts with hibernate  Can u send me Realtime example of struts with hibernate(Saving,Delete,update,select from muliple tables
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
java - Struts
java  hi i m working on a project in which i have to create a page in which i have to give an feature in which one can create a add project template in which one can add modules and inside those modules some more options please

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.