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

📄 addroleaction.java

📁 教师办公管理系统
💻 JAVA
字号:
package to.view.Action;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import java.io.IOException;
import javax.servlet.ServletException;
import to.model.Role.RoleBean;
import to.model.Role.RoleItem;
import to.view.FormBean.AddRoleFormBean;

public class AddRoleAction extends Action 
{
  /**
   * This is the main action called from the Struts framework.
   * @param mapping The ActionMapping used to select this instance.
   * @param form The optional ActionForm bean for this request.
   * @param request The HTTP Request we are processing.
   * @param response The HTTP Response we are processing.
   * @throws javax.servlet.ServletException
   * @throws java.io.IOException
   * @return 
   */
  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  {
    
    AddRoleFormBean arfb=(AddRoleFormBean)form;
    
    //接受form值
    String RoleName=request.getParameter("RoleName").trim();
    int RightID=Integer.parseInt(request.getParameter("RightID"));
    

    RoleBean rb=new RoleBean();
    RoleItem ri=new RoleItem();
    
    //更新值
    ri.setRoleID(0);
    ri.setRoleName(RoleName);
    ri.setRightID(RightID);
    
    //判断非空
    if(RoleName==null||RoleName.length()<1)
    {
       request.setAttribute("question","角色名称不能为空!");
       return mapping.findForward("failure");
    }
    else if(RightID==0)
    {
      request.setAttribute("question","角色权限不能为空!");
      return mapping.findForward("failure");
    }
    
    
    if(rb.insertRole(ri).equals("添加成功"))
    {
      return mapping.findForward("success");
    }
    request.setAttribute("question","添加失败");
    return mapping.findForward("failure");

  }
}

⌨️ 快捷键说明

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