Modifying the web.xml file – HP Integrity NonStop J-Series User Manual

Page 111

Advertising
background image

.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, the 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<String, String> model = new HashMap<String, String>();
model
.put("add",
"Transaction Complete - One Employee Added to Employee Database");
return new ModelAndView("insertresult", "model", model);
}

}

Modifying the web.xml File

To modify the web.xml in the EmpInfo/WebContent/ directory, complete the following steps:
1.

Add ContextLoaderListener to load the applicationContext.xml file under the
<web-app>

tag:

Overview of EmpInfo

111

Advertising
This manual is related to the following products: