SaveCustomerAction.java

package com.dotj.web.struts; 
 
import java.util.Locale; 
import javax.servlet.http.HttpSession; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
 
import org.apache.commons.logging.Log; 
import org.apache.commons.logging.LogFactory; 
import org.apache.struts.action.Action; 
import org.apache.struts.action.ActionForm; 
import org.apache.struts.action.ActionForward; 
import org.apache.struts.action.ActionMapping; 
import org.apache.struts.util.MessageResources; 
import com.dotj.base.Util; 
 
 
public final class SaveCustomerAction extends Action { 
    /** 
     * The <code>Log</code> instance for this application. 
     */ 
    protected static Log log = 
            LogFactory.getLog(SaveCustomerAction.class); 
 
 
    // --------------------------------------------------------- Public Methods
/** * Process the specified HTTP request, and create the corresponding HTTP * response (or forward to another web component that will create it). * Return an <code>ActionForward</code> instance describing where and how * control should be forwarded, or <code>null</code> if the response has * already been completed. * * @param mapping The ActionMapping used to select this instance * @param form The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * @throws Exception if the application business logic throws * an exception */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Extract attributes we will need Locale locale = getLocale(request); MessageResources messages = getResources(request); HttpSession session = request.getSession(); // Set a transactional control token to prevent double posting if (log.isTraceEnabled()) { log.trace(" Setting transactional control token"); } saveToken(request); CustomerForm customerForm = (CustomerForm) form; String employed = (customerForm.getEmployed() == null || customerForm.getEmployed().length() == 0) ? "N" : "Y"; String sql = "UPDATE customer " + "SET FirstName = '" + Util.replace(customerForm.getFirstName(), "'", "''") + "'" + ", LastName = '" + Util.replace(customerForm.getLastName(), "'", "''") + "'" + ", City = '" + Util.replace(customerForm.getCity(), "'", "''") + "'" + ", State = '" + customerForm.getState() + "'" + ", Zip = '" + Util.replace(customerForm.getZipCode(), "'", "''") + "'" + ", Country = '" + customerForm.getCountry() + "'" + ", Gender = '" + customerForm.getGender() + "'" + ", Employed = '" + employed + "'" + ", Comments = '" + Util.replace(customerForm.getComments(), "'", "''") + "'" + ", Approved = '" + customerForm.getApproved() + "'" + " WHERE Id = 1"; int count = JDBCUtil.executeUpdate(servlet.getServletContext(), sql); if (mapping.getAttribute() != null) { if ("request".equals(mapping.getScope())) request.removeAttribute(mapping.getAttribute()); else session.removeAttribute(mapping.getAttribute()); } // Forward control to the edit user registration page if (log.isTraceEnabled()) { log.trace(" Forwarding to 'success' page"); } return (mapping.findForward("success")); } }