package zsn.web.actions;
import java.io.FileOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
import zsn.business.manager.Manager;
import zsn.business.model.Department;
import zsn.business.model.Employee;
import zsn.business.util.PageModel;
import zsn.web.forms.DepartmentActionForm;
import zsn.web.forms.EmployeesActionForm;
public class EmployeesAction extends BaseAction {
private Manager employeesManager;
private String uploadPath;
public void setEmployeesManager(Manager employeesManager) {
this.employeesManager = employeesManager;
}
public void setUploadPath(String uploadPath) {
this.uploadPath = uploadPath;
}
protected ActionForward unspecified(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
System.out.println("DepartmentAction=>>unspecified()");
ActionForward listActionForward = new ActionForward("/index.jsp", true);
return listActionForward;
}
public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
EmployeesActionForm iaf = (EmployeesActionForm)form;
Employee item = new Employee();
BeanUtils.copyProperties(item, iaf);
employeesManager.addItem(item);
ActionForward af = new ActionForward("employee.do?command=list&pageNo=" +
iaf.getPageNo() +
"&pageSize=" + iaf.getPageSize(), true);
return af;
}
public ActionForward del(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
EmployeesActionForm iaf = (EmployeesActionForm)form;
employeesManager.deleteItem(iaf.getSelectFlag());
ActionForward af = new ActionForward("employee.do?command=list&pageNo=" +
iaf.getPageNo() +
"&pageSize=" + iaf.getPageSize(), true);
return af;
}
public ActionForward modifyDetail(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
EmployeesActionForm iaf = (EmployeesActionForm)form;
Employee item =(Employee)employeesManager.findItemById(iaf.getId());
request.setAttribute("item", item);
return mapping.findForward("modify_detail");
}
public ActionForward modify(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
EmployeesActionForm iaf = (EmployeesActionForm)form;
Employee item = new Employee();
BeanUtils.copyProperties(item, iaf);
employeesManager.modifyItem(item);
ActionForward af = new ActionForward("employee.do?command=list&pageNo=" +
iaf.getPageNo() +
"&pageSize=" + iaf.getPageSize(), true);
return af;
}
public ActionForward findDetail(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
EmployeesActionForm iaf = (EmployeesActionForm)form;
Employee item =(Employee)employeesManager.findItemById(iaf.getId());
request.setAttribute("item", item);
return mapping.findForward("find_detail");
}
public ActionForward list(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
EmployeesActionForm iaf = (EmployeesActionForm)form;
PageModel pageModel = employeesManager.findAllItem(iaf.getPageNo(), iaf.getPageSize(), iaf.getClientIdOrName());
request.setAttribute("pagemodel", pageModel);
return mapping.findForward("list_success");
}
public ActionForward fuck(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
EmployeesActionForm iaf = (EmployeesActionForm)form;
PageModel pageModel = employeesManager.fuck(iaf.getPageNo(), iaf.getPageSize());
request.setAttribute("pagemodel", pageModel);
return mapping.findForward("list_success");
}
public ActionForward uploadDetail(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
EmployeesActionForm iaf = (EmployeesActionForm)form;
Employee item =(Employee)employeesManager.findItemById(iaf.getId());
request.setAttribute("item", item);
return mapping.findForward("upload_detail");
}
public ActionForward upload(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
EmployeesActionForm iaf = (EmployeesActionForm)form;
FormFile myFile = iaf.getFileName();
if(myFile != null){
FileOutputStream fos = new FileOutputStream(this.uploadPath + iaf.getId() + ".gif");
fos.write(myFile.getFileData());
fos.flush();
fos.close();
}
ActionForward af = new ActionForward("employee.do?command=list&pageNo=" +
iaf.getPageNo() +
"&pageSize=" + iaf.getPageSize(), true);
return af;
}
public ActionForward jump(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
return mapping.findForward("jump");
}
}
- 1
- 2
前往页