Modifying the employeecontroller.java file – HP Integrity NonStop J-Series User Manual
Page 77

}
public String getLastname () {
return lastname;
}
public void setLastname (String lastname) {
this. lastname= lastname;
}
public int getAge () {
return age;
}
public void setAge (int age) {
this. age= age;
}
public String getEmail () {
return email;
}
public void setEmail (String email) {
this. email= email;
}
}
Modifying the EmployeeController.java File
The EmployeeController.java file in the com.hp.empinfo.web package is modified to
map the retrieve or delete request to the underlying database operations.
After modification, the EmployeeController.java file appears as:
package com.hp.empinfo.web;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.ServletException;
import com.hp.empinfo.domain.Employee;
import com.hp.empinfo.service.EmployeeDao;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
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();
String rord = ((Employee) command).getRord();
if (rord!=null && rord.equalsIgnoreCase("Retrieve")) {
Employee emp1 = empdao.getDetail(empid);
Map
model.put("empid", "" + emp1.getEmpid());
model.put("empfn", emp1.getFirstname());
Getting Started with Spring
77