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

📄 employeeservlet.java

📁 < J2EE应用开发详解>>一书全部的源代码. 本书基于J2EE 1.4平台
💻 JAVA
字号:
package com.j2ee14.ch18;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.ejb.*;
/**
 *和雇员信息管理相关的Servlet
 */
public class EmployeeServlet extends MyBaseServlet
{
    /**
     *执行HTTP处理
     */    
    public  void doProcess(HttpServletRequest request, HttpServletResponse response) 
                throws ServletException, IOException
    {
    	String nextPage="main.jsp";
    	try
    	{
    	  
    	    String action=request.getParameter("action");   	    		
	    	if(action.equals("add")) addEmployee(getEmployeeInfo(request,response));	    		
	    	if(action.equals("view"))
	    	{

	    		nextPage="modifyEmployee.jsp";
	    		request.setAttribute("employeeInfo",viewEmployee((String)request.getParameter("employeeId")));
	    	}
	    	if(action.equals("modify")) modifyEmployee(getEmployeeInfo(request,response));
	    	if(action.equals("remove")) removeEmployee((String)request.getParameter("employeeId"));
	    	request.setAttribute("msg","操作成功");
	        
       }
       catch(Exception e)
       {
       	 e.printStackTrace();
       	  request.setAttribute("exception",e);
       }
    
       RequestDispatcher requestDispatcher = request.getRequestDispatcher(nextPage);
	   requestDispatcher.forward(request, response);
    }
    
    /**
     *获得请求中的参数
     */
    private EmployeeInfo getEmployeeInfo(HttpServletRequest request, HttpServletResponse response) 
                throws ServletException, IOException
    {
    	EmployeeInfo ret=new EmployeeInfo();
        ret.employeeId=(String)request.getParameter("employeeId");
        ret.baseSalary=Float.parseFloat((String)request.getParameter("baseSalary"));
        ret.overTimeSalary=Float.parseFloat((String)request.getParameter("overTimeSalary"));
        ret.employeeName=(String)request.getParameter("employeeName");
        return ret;
    }
    /**
     * 增加雇员
     */
    public void addEmployee    (EmployeeInfo info)  
    { 
		try
		{
			SalaryFacadeLocal facade=this.getSalaryFacadeLocal();
			facade.addEmployee(info);
		}
		catch(ServiceLocatorException e)
		{
			e.printStackTrace();
		}
		catch(CreateException e)
		{
			e.printStackTrace();
		}
		
				
    }
    
    /**
     * 删除一个雇员信息
     */
    public void removeEmployee    (String id)  
    { 
	    try
		{
			SalaryFacadeLocal facade=this.getSalaryFacadeLocal();
			facade.removeEmployee(id);
		}
		catch(ServiceLocatorException e)
		{
			e.printStackTrace();
		}
		catch(CreateException e)
		{
			e.printStackTrace();
		}
    }
    
    /**
     * 增加雇员
     */
    public void modifyEmployee    (EmployeeInfo info)  
    { 
      	try
		{
			SalaryFacadeLocal facade=this.getSalaryFacadeLocal();
			facade.modifyEmployeeInfo(info);
		}
		catch(ServiceLocatorException e)
		{
			e.printStackTrace();
		}
		catch(CreateException e)
		{
			e.printStackTrace();
		} 
    }
    /**
     *查看雇员信息,返回值对象
     */
    public  EmployeeInfo   viewEmployee (String id)  
    { 
      	try
		{
			SalaryFacadeLocal facade=this.getSalaryFacadeLocal();
			return facade.viewEmployee(id);
		}
		catch(ServiceLocatorException e)
		{
			e.printStackTrace();
			return null;
		}
		catch(CreateException e)
		{
			e.printStackTrace();
			return null;
		}     	

    }    
         
   
}

⌨️ 快捷键说明

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