Here i am using struts 1.0 to view my sql table values on jsp page. But the problem is when i append the value in bean then i find the last row of table is shown repetedly. Any one have solution for this please help me.
AzAddNewCustomerAction .java package aquazone; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; import java.util.ArrayList; import java.util.ResourceBundle; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.regex.Pattern; 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 AzAddNewCustomerAction extends Action{ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { AzAddNewCustomerBean azAddNewCustomerBean=(AzAddNewCustomerBean)form; String userId=azAddNewCustomerBean.getUserId(); String userName=azAddNewCustomerBean.getUserName(); String mobileNumber=azAddNewCustomerBean.getMobileNumber(); String bookingDate=azAddNewCustomerBean.getBookingDate(); String addressStreet=azAddNewCustomerBean.getAddressStreet(); String addressCity=azAddNewCustomerBean.getAddressCity(); String addressDistrict=azAddNewCustomerBean.getAddressDistrict(); String addressPostalCode=azAddNewCustomerBean.getAddressPostalCode(); String deliveryAddressStreet=azAddNewCustomerBean.getDeliveryAddressStreet(); String deliveryAddressCity=azAddNewCustomerBean.getDeliveryAddressCity(); String deliveryAddressDistrict=azAddNewCustomerBean.getDeliveryAddressDistrict(); String deliveryAddressPostalCode=azAddNewCustomerBean.getDeliveryAddressPostalCode(); String buttonValue=azAddNewCustomerBean.getButtonValue(); ResourceBundle resourceBundle=ResourceBundle.getBundle("MessageResources"); String userIdMissingError=resourceBundle.getString("azAddNewCustomerError.userIdMissing"); String userNameMissingError=resourceBundle.getString("azAddNewCustomerError.userNameMissing"); String mobileNumberMissingError=resourceBundle.getString("azAddNewCustomerError.mobileNumberMissing"); String mobileNumberLengthError=resourceBundle.getString("azAddNewCustomerError.mobileNumberLength"); String bookingDateMissingError=resourceBundle.getString("azAddNewCustomerError.bookingDateMissing"); String bookingDateFormatError=resourceBundle.getString("azAddNewCustomerError.bookingDateFormat"); String addressStreetMissingError=resourceBundle.getString("azAddNewCustomerError.addressStreetMissing"); String addressCityMissingError=resourceBundle.getString("azAddNewCustomerError.addressCityMissing"); String aaddressDistrictMissingError=resourceBundle.getString("azAddNewCustomerError.aaddressDistrictMissing"); String addressPostalCodeMissingError=resourceBundle.getString("azAddNewCustomerError.addressPostalCodeMissing"); String addressPostalCodeLengthError=resourceBundle.getString("azAddNewCustomerError.addressPostalCodeLength"); String deliveryAddressStreetMissingError=resourceBundle.getString("azAddNewCustomerError.deliveryAddressStreetMissing"); String deliveryAddressCityMissingError=resourceBundle.getString("azAddNewCustomerError.deliveryAddressCityMissing"); String deliveryAddressDistrictMissingError=resourceBundle.getString("azAddNewCustomerError.deliveryAddressDistrictMissing"); String deliveryAddressPostalCodeMissingError=resourceBundle.getString("azAddNewCustomerError.deliveryAddressPostalCodeMissing"); String deliveryAddressPostalCodeLengthError=resourceBundle.getString("azAddNewCustomerError.deliveryAddressPostalCodeLength"); String searchButton=resourceBundle.getString("azAddNewCustomer.search"); String nextButton=resourceBundle.getString("azAddNewCustomer.next"); String modifyButton=resourceBundle.getString("azAddNewCustomer.modify"); String deleteButton=resourceBundle.getString("azAddNewCustomer.delete"); String dateFormatPattern="[0-9]{2}/[0-9]{2}/[0-9]{4}"; Connection connect = AzDAOConnect.daoConnect(); ArrayList<AzAddNewCustomerBean> list = new ArrayList<AzAddNewCustomerBean>(); if(buttonValue.equals(searchButton)) { try { Statement statement = connect.createStatement(); ResultSet resultSet=statement.executeQuery("select * from azaddnewcustomer"); while (resultSet.next()) { azAddNewCustomerBean.setUserId(resultSet.getString("userId_db")); azAddNewCustomerBean.setUserName(resultSet.getString("userName_db")); azAddNewCustomerBean.setMobileNumber(resultSet.getString("mobileNumber_db")); azAddNewCustomerBean.setBookingDate(resultSet.getString("bookingDate_db")); azAddNewCustomerBean.setAddressStreet(resultSet.getString("street_db")); azAddNewCustomerBean.setAddressCity(resultSet.getString("city_db")); azAddNewCustomerBean.setAddressDistrict(resultSet.getString("district_db")); azAddNewCustomerBean.setAddressPostalCode(resultSet.getString("postalCode_db")); azAddNewCustomerBean.setDeliveryAddressStreet(resultSet.getString("streetDelivery_db")); azAddNewCustomerBean.setDeliveryAddressCity(resultSet.getString("cityDelivery_db")); azAddNewCustomerBean.setDeliveryAddressDistrict(resultSet.getString("districtDelivery_db")); azAddNewCustomerBean.setDeliveryAddressPostalCode(resultSet.getString("postalCodeDelivery_db")); list.add(azAddNewCustomerBean); } azAddNewCustomerBean.setList(list); connect.close(); } catch (Exception e) { System.out.println("Check my error: "+e); connect.close(); } return(mapping.findForward("correctValueSearch")); } if(userId.length()<1 || userId==null) { azAddNewCustomerBean.setWarning(userIdMissingError); return(mapping.findForward("inCorrectValue")); } else if(userName.length()<1 || userName==null) { azAddNewCustomerBean.setWarning(userNameMissingError); return(mapping.findForward("inCorrectValue")); } else if(mobileNumber.length()<1 || mobileNumber==null) { azAddNewCustomerBean.setWarning(mobileNumberMissingError); return(mapping.findForward("inCorrectValue")); } else if(mobileNumber.length()!=10) { azAddNewCustomerBean.setWarning(mobileNumberLengthError); return(mapping.findForward("inCorrectValue")); } else if(bookingDate.length()<1 || bookingDate==null) { azAddNewCustomerBean.setWarning(bookingDateMissingError); return(mapping.findForward("inCorrectValue")); } else if(!(Pattern.matches(dateFormatPattern,bookingDate))) { azAddNewCustomerBean.setWarning(bookingDateFormatError); return(mapping.findForward("inCorrectValue")); } else if(addressStreet.length()<1 || addressStreet==null) { azAddNewCustomerBean.setWarning(addressStreetMissingError); return(mapping.findForward("inCorrectValue")); } else if(addressCity.length()<1 || addressCity==null) { azAddNewCustomerBean.setWarning(addressCityMissingError); return(mapping.findForward("inCorrectValue")); } else if(addressDistrict.length()<1 || addressDistrict==null) { azAddNewCustomerBean.setWarning(aaddressDistrictMissingError); return(mapping.findForward("inCorrectValue")); } else if(addressPostalCode.length()<1 || addressPostalCode==null) { azAddNewCustomerBean.setWarning(addressPostalCodeMissingError); return(mapping.findForward("inCorrectValue")); } else if(addressPostalCode.length()!=6) { azAddNewCustomerBean.setWarning(addressPostalCodeLengthError); return(mapping.findForward("inCorrectValue")); } else if(deliveryAddressStreet.length()<1 || deliveryAddressStreet==null) { azAddNewCustomerBean.setWarning(deliveryAddressStreetMissingError); return(mapping.findForward("inCorrectValue")); } else if(deliveryAddressCity.length()<1 || deliveryAddressCity==null) { azAddNewCustomerBean.setWarning(deliveryAddressCityMissingError); return(mapping.findForward("inCorrectValue")); } else if(deliveryAddressDistrict.length()<1 || deliveryAddressDistrict==null) { azAddNewCustomerBean.setWarning(deliveryAddressDistrictMissingError); return(mapping.findForward("inCorrectValue")); } else if(deliveryAddressPostalCode.length()<1 || deliveryAddressPostalCode==null) { azAddNewCustomerBean.setWarning(deliveryAddressPostalCodeMissingError); return(mapping.findForward("inCorrectValue")); } else if(deliveryAddressPostalCode.length()!=6) { azAddNewCustomerBean.setWarning(deliveryAddressPostalCodeLengthError); return(mapping.findForward("inCorrectValue")); } else { if(buttonValue.equals(nextButton)) { try { String azAddNewCustomerQuery = "{call AzAddNewCustomerProcedure(?,?,?,?,?,?,?,?,?,?,?,?)}"; CallableStatement callableStatement = connect.prepareCall(azAddNewCustomerQuery); callableStatement.setString(1,userId); callableStatement.setString(2,userName); callableStatement.setString(3,mobileNumber); callableStatement.setString(4,bookingDate); callableStatement.setString(5,addressStreet); callableStatement.setString(6,addressCity); callableStatement.setString(7,addressDistrict); callableStatement.setString(8,addressPostalCode); callableStatement.setString(9,deliveryAddressStreet); callableStatement.setString(10,deliveryAddressCity); callableStatement.setString(11,deliveryAddressDistrict); callableStatement.setString(12,deliveryAddressPostalCode); callableStatement.execute(); connect.close(); } catch (Exception e) { System.out.println("Check my error: "+e); connect.close(); } return(mapping.findForward("correctValueNext")); } if(buttonValue.equals(modifyButton)) { try { String azAddNewCustomerQuery = "{call AzUpdateNewCustomerProcedure(?,?,?,?,?,?,?,?,?,?,?,?)}"; CallableStatement callableStatement = connect.prepareCall(azAddNewCustomerQuery); callableStatement.setString(1,userId); callableStatement.setString(2,userName); callableStatement.setString(3,mobileNumber); callableStatement.setString(4,bookingDate); callableStatement.setString(5,addressStreet); callableStatement.setString(6,addressCity); callableStatement.setString(7,addressDistrict); callableStatement.setString(8,addressPostalCode); callableStatement.setString(9,deliveryAddressStreet); callableStatement.setString(10,deliveryAddressCity); callableStatement.setString(11,deliveryAddressDistrict); callableStatement.setString(12,deliveryAddressPostalCode); callableStatement.execute(); connect.close(); } catch (Exception e) { System.out.println("Check my error: "+e); connect.close(); } return(mapping.findForward("correctValueModify")); } if(buttonValue.equals(deleteButton)) { return(mapping.findForward("correctValueDelete")); } else { return(mapping.findForward("buttonNullValue")); } } } } AzAddNewCustomerBean .java package aquazone; import java.util.ArrayList; import org.apache.struts.action.ActionForm; public class AzAddNewCustomerBean extends ActionForm { private String userId; private String userName; private String mobileNumber; private String bookingDate; private String addressStreet; private String addressCity; private String addressDistrict; private String addressPostalCode; private String copyAddress; private String deliveryAddressStreet; private String deliveryAddressCity; private String deliveryAddressDistrict; private String deliveryAddressPostalCode; private String buttonValue; private String warning; ArrayList<AzAddNewCustomerBean> list = new ArrayList<AzAddNewCustomerBean>(); public String getUserId() { return(userId); } public void setUserId(String userId) { this.userId=userId; } public String getUserName() { return(userName); } public void setUserName(String userName) { this.userName=userName; } public String getMobileNumber() { return(mobileNumber); } public void setMobileNumber(String mobileNumber) { this.mobileNumber=mobileNumber; } public String getBookingDate() { return(bookingDate); } public void setBookingDate(String bookingDate) { this.bookingDate=bookingDate; } public String getAddressStreet() { return(addressStreet); } public void setAddressStreet(String addressStreet) { this.addressStreet=addressStreet; } public String getAddressCity() { return(addressCity); } public void setAddressCity(String addressCity) { this.addressCity=addressCity; } public String getAddressDistrict() { return(addressDistrict); } public void setAddressDistrict(String addressDistrict) { this.addressDistrict=addressDistrict; } public String getAddressPostalCode() { return(addressPostalCode); } public void setAddressPostalCode(String addressPostalCode) { this.addressPostalCode=addressPostalCode; } public String getCopyAddress() { return(copyAddress); } public void setCopyAddress(String copyAddress) { this.copyAddress=copyAddress; } public String getDeliveryAddressStreet() { return(deliveryAddressStreet); } public void setDeliveryAddressStreet(String deliveryAddressStreet) { this.deliveryAddressStreet=deliveryAddressStreet; } public String getDeliveryAddressCity() { return(deliveryAddressCity); } public void setDeliveryAddressCity(String deliveryAddressCity) { this.deliveryAddressCity=deliveryAddressCity; } public String getDeliveryAddressDistrict() { return(deliveryAddressDistrict); } public void setDeliveryAddressDistrict(String deliveryAddressDistrict) { this.deliveryAddressDistrict=deliveryAddressDistrict; } public String getDeliveryAddressPostalCode() { return(deliveryAddressPostalCode); } public void setDeliveryAddressPostalCode(String deliveryAddressPostalCode) { this.deliveryAddressPostalCode=deliveryAddressPostalCode; } public String getButtonValue() { return(buttonValue); } public void setButtonValue(String buttonValue) { this.buttonValue=buttonValue; } public String getWarning() { return(warning); } public void setWarning(String warning) { this.warning=warning; } public ArrayList<AzAddNewCustomerBean> getList() { return list; } public void setList(ArrayList<AzAddNewCustomerBean> list) { this.list=list; } } azAddNewCustomer.jsp <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ page contentType="text/html;charset=windows-1252"%> <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/> <title><bean:message key="azAddNewCustomer.azAddNewCustomerTitle"/></title> <script> function copyAddressFunction() { var copyAddressVar = document.getElementById("copyAddressVar"); var addressStreetVar = document.getElementById("addressStreetVar"); var addressCityVar = document.getElementById("addressCityVar"); var addressDistrictVar = document.getElementById("addressDistrictVar"); var addressPostalCodeVar = document.getElementById("addressPostalCodeVar"); var deliveryAddressStreetVar = document.getElementById("deliveryAddressStreetVar"); var deliveryAddressCityVar = document.getElementById("deliveryAddressCityVar"); var deliveryAddressDistrictVar = document.getElementById("deliveryAddressDistrictVar"); var deliveryAddressPostalCodeVar = document.getElementById("deliveryAddressPostalCodeVar"); if (copyAddressVar.checked) { deliveryAddressStreetVar.value = addressStreetVar.value; deliveryAddressCityVar.value = addressCityVar.value; deliveryAddressDistrictVar.value = addressDistrictVar.value; deliveryAddressPostalCodeVar.value = addressPostalCodeVar.value; } else { deliveryAddressStreetVar.value = null; deliveryAddressCityVar.value = null; deliveryAddressDistrictVar.value = null; deliveryAddressPostalCodeVar.value = null; } } </script> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" /> <script src="http://code.jquery.com/jquery-1.8.3.js"></script> <script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script> <script type="text/javascript" language="javascript"> $(document).ready( function() { $("#bookingDate").datepicker(); } ); </script> </head> <body> <html:form action="/actions/azAddNewCustomer"> <center> <bean:message key="azAddNewCustomer.userId"/> <html:text property="userId"/><br> <bean:message key="azAddNewCustomer.userName"/> <html:text property="userName"/><br> <bean:message key="azAddNewCustomer.moblieNumber"/> <html:text property="mobileNumber"/><br> <bean:message key="azAddNewCustomer.bookingDate"/> <html:text property="bookingDate" styleId="bookingDate"/><br> <bean:message key="azAddNewCustomer.address"/><br> <bean:message key="azAddNewCustomer.addressStreet"/> <html:text property="addressStreet" styleId="addressStreetVar"/><br> <bean:message key="azAddNewCustomer.addressCity"/> <html:text property="addressCity" styleId="addressCityVar"/><br> <bean:message key="azAddNewCustomer.addressDistrict"/> <html:text property="addressDistrict" styleId="addressDistrictVar"/><br> <bean:message key="azAddNewCustomer.addressPostalCode"/> <html:text property="addressPostalCode" styleId="addressPostalCodeVar"/><br> <html:checkbox property="copyAddress" styleId="copyAddressVar" onclick="copyAddressFunction()"/> <bean:message key="azAddNewCustomer.copyAddress"/><br> <bean:message key="azAddNewCustomer.deliveryAddress"/><br> <bean:message key="azAddNewCustomer.deliveryAddressStreet"/> <html:text property="deliveryAddressStreet" styleId="deliveryAddressStreetVar"/><br> <bean:message key="azAddNewCustomer.deliveryAddressCity"/> <html:text property="deliveryAddressCity" styleId="deliveryAddressCityVar"/><br> <bean:message key="azAddNewCustomer.deliveryAddressDistrict"/> <html:text property="deliveryAddressDistrict" styleId="deliveryAddressDistrictVar"/><br> <bean:message key="azAddNewCustomer.deliveryAddressPostalCode"/> <html:text property="deliveryAddressPostalCode" styleId="deliveryAddressPostalCodeVar"/><br> <bean:write name="azAddNewCustomerBean" property="warning" filter="false"/><br> <html:submit property="buttonValue"> <bean:message key="azAddNewCustomer.next"/> </html:submit> <html:submit property="buttonValue"> <bean:message key="azAddNewCustomer.modify"/> </html:submit> <html:submit property="buttonValue"> <bean:message key="azAddNewCustomer.delete"/> </html:submit> <html:submit property="buttonValue"> <bean:message key="azAddNewCustomer.search"/> </html:submit> <html:reset> <bean:message key="azAddNewCustomer.reset"/> </html:reset><br> <%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%> <logic:iterate name="azAddNewCustomerBean" id="azAddNewCustomerBean" property="list"> <fieldset> <bean:write name="azAddNewCustomerBean" property="userId"/> <bean:write name="azAddNewCustomerBean" property="userName"/> <bean:write name="azAddNewCustomerBean" property="mobileNumber"/> <bean:write name="azAddNewCustomerBean" property="bookingDate"/> <bean:write name="azAddNewCustomerBean" property="addressStreet"/> <bean:write name="azAddNewCustomerBean" property="addressCity"/> <bean:write name="azAddNewCustomerBean" property="addressDistrict"/> <bean:write name="azAddNewCustomerBean" property="addressPostalCode"/> <bean:write name="azAddNewCustomerBean" property="deliveryAddressStreet"/> <bean:write name="azAddNewCustomerBean" property="deliveryAddressDistrict"/> <bean:write name="azAddNewCustomerBean" property="deliveryAddressPostalCode"/> </fieldset> </logic:iterate> </center> </html:form> </body> </html>
Ads