📄 validateemployeeaction.java
字号:
package com.example;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.List;
public class ValidateEmployeeAction extends Action {
public ActionForward perform(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException {
ActionErrors errors = new ActionErrors();
EmployeeForm empForm = (EmployeeForm)form;
String name = empForm.getName();
if(name.trim().equals("")) {
ActionError error = new ActionError("error.missing.name");
errors.add(ActionErrors.GLOBAL_ERROR,error);
}
String department = empForm.getDepartment();
if(department.trim().equals("")) {
ActionError error = new ActionError("error.missing.department");
errors.add("ActionErrors.GLOBAL_ERROR",error);
}
String[] skills = empForm.getSkills();
if(skills == null) {
ActionError error = new ActionError("error.missing.skills");
errors.add("ActionErrors.GLOBAL_ERROR",error);
}
if(errors.size() > 0) {
saveErrors(request,errors);
return new ActionForward(mapping.getInput());
}
return mapping.findForward("success");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -