HP Integrity NonStop H-Series User Manual
Page 126

int age = ((Employee) command).getAge();
String email = ((Employee) command).getEmail();
empdao.insertDetail(empid, firstname, lastname, age, email);
Map
model
.put("add",
"Transaction Complete - One Employee Added to Employee Database");
return new ModelAndView("insertresult", "model", model);
}
3.
Add the following
import
statements to include the classes used in the controller.
import com.hp.empinfo.domain.Employee;
import com.hp.empinfo.service.EmployeeDao;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
After incorporating the above modifications, your
EmployeeController.java
controller
class must appear as:
package com.hp.empinfo.web;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.ServletException;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.IOException;
import com.hp.empinfo.domain.Employee;
import com.hp.empinfo.service.EmployeeDao;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
public class EmployeeController extends SimpleFormController {
private EmployeeDao empdao;
public ModelAndView onSubmit(Object command) throws ServletException,
SQLException {
WebApplicationContext wac = WebApplicationContextUtils
.getRequiredWebApplicationContext(getServletContext());
empdao = (EmployeeDao) wac.getBean("empdao");
int empid = ((Employee) command).getEmpid();
String firstname = ((Employee) command).getFirstname();
String lastname = ((Employee) command).getLastname();
int age = ((Employee) command).getAge();
String email = ((Employee) command).getEmail();
empdao.insertDetail(empid, firstname, lastname, age, email);
Map
model
.put("add",
"Transaction Complete - One Employee Added to Employee Database");
return new ModelAndView("insertresult", "model", model);
}
}
126
Getting Started with Spring