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

Page 120

Advertising
background image

}
public int getEmpid() {
return empid;
}
public void setEmpid(int empid) {
this.empid = empid;
}
public String getFirstname() {
return firstname;
}
public void setFirstname (String firstname) {
this. firstname= firstname;
}
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();

120 Getting Started with Spring

Advertising
This manual is related to the following products: