//Created by MyEclipse Struts
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.0.1/xslt/JavaClass.xsl
package com.yourcompany.struts.action;
import java.sql.Connection;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.DynaValidatorForm;
import com.demo.beans.Myaddr;
import com.demo.dao.OracleDao;
/**
* MyEclipse Struts
* Creation date: 08-18-2006
*
* XDoclet definition:
* @struts.action path="/add" name="addForm" input="/error.jsp" scope="request" validate="true"
* @struts.action-forward name="success" path="/index.jsp"
*/
public class AddAction extends Action {
// --------------------------------------------------------- Instance Variables
// --------------------------------------------------------- Methods
private OracleDao oracle;
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
DynaValidatorForm addForm = (DynaValidatorForm) form;
// TODO Auto-generated method stub
Myaddr myaddr = new Myaddr();
Connection conn = null;
myaddr.setId((Integer)addForm.get("id"));
myaddr.setFirstName((String)addForm.get("firstName"));
myaddr.setLastName((String)addForm.get("lastName"));
myaddr.setJobTitle((String)addForm.get("jobTitle"));
myaddr.setDepartment((String)addForm.get("department"));
myaddr.setOffph((Integer)addForm.get("offph"));
myaddr.setMobile((Integer)addForm.get("mobile"));
myaddr.setEmail((String)addForm.get("email"));
try {
conn = this.getDataSource(request).getConnection();
oracle = new OracleDao(conn);
if(rand.equals(input)&&oracle.save(myaddr))
{
return mapping.findForward("success");
}
else
{
ActionErrors errors = new ActionErrors();
errors.add("error",new ActionError("litao"));
this.saveErrors(request,errors);
return new ActionForward(mapping.getInput());
}
}
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}