⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addemployeeaction.java

📁 Struts框架下的练手例子 有兴趣
💻 JAVA
字号:
package com.wrox;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.apache.struts.action.ActionErrors;import org.apache.struts.action.ActionError;public class AddEmployeeAction extends Action {  public ActionForward execute(ActionMapping mapping,    ActionForm form,    HttpServletRequest request,    HttpServletResponse response)    throws IOException, ServletException {    // Default target to success    String target = new String("success");    if ( isCancelled(request) ) {      // Cancel pressed back to employee list      return (mapping.findForward("success"));    }    try {      Employee employee = new Employee();      EmployeeForm employeeForm = (EmployeeForm) form;      employee.setUsername(employeeForm.getUsername());      employee.setPassword(employeeForm.getPassword());      employee.setRoleid(new Integer(employeeForm.getRoleid()));      employee.setName(employeeForm.getName());      employee.setPhone(employeeForm.getPhone());      employee.setEmail(employeeForm.getEmail());      employee.setDepid(new Integer(employeeForm.getDepid()));      EmployeeData.addEmployee(employee, getDataSource(request));    }    catch ( Exception e ) {      System.err.println("Setting target to error");      target = new String("error");      ActionErrors errors = new ActionErrors();      errors.add(ActionErrors.GLOBAL_ERROR,        new ActionError("errors.database.error", e.getMessage()));      // Report any errors      if ( !errors.isEmpty() ) {        saveErrors(request, errors);      }    }    // Forward to the appropriate View    return (mapping.findForward(target));  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -