Improving the controller – HP Integrity NonStop H-Series User Manual
Page 125
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
Improving the Controller
Modify the
EmployeeController.java
file to perform the employee database transactions.
To modify the
EmployeeController.java
file, complete the following steps:
1.
Add a reference to the
EmployeeDao.java
in the
EmployeeController.java
controller
class as shown below:
private EmployeeDao empdao;
2.
Replace the
onSubmit
method with the
handleRequest
method.
This is done to:
1.
Recognize the inputs from the View
2.
Pass the recognized inputs to the Model
3.
Pass the output back to the View
Before modification:
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String now = (new Date()).toString();
logger.info("Returning view with " + now);
return new ModelAndView("insert", "now", now);
}
After modification:
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();
Overview of EmpInfo
125