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

📄 teachersbean.java

📁 基于strurs架构+servlet+jsp+javabean架构科研管理系统
💻 JAVA
字号:
/*
 * Created on 2008-6-9
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package cn.edu.zucc.research.ejb.session.teacher;

import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;

import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.ejb.RemoveException;
import javax.ejb.SessionBean;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import cn.edu.zucc.research.ejb.cmp.admin.Admin;
import cn.edu.zucc.research.ejb.cmp.teacher.Teacher;
import cn.edu.zucc.research.ejb.cmp.teacher.TeacherHome;
import cn.edu.zucc.research.exception.ResearchException;
import cn.edu.zucc.research.model.AdminLogin;
import cn.edu.zucc.research.model.TeacherLogin;


/**
 *
 * <!-- begin-user-doc --> A generated session bean <!-- end-user-doc --> *
 <!-- lomboz.beginDefinition -->
 <?xml version="1.0" encoding="UTF-8"?>
 <lomboz:EJB xmlns:j2ee="http://java.sun.com/xml/ns/j2ee" xmlns:lomboz="http://lomboz.objectlearn.com/xml/lomboz">
 <lomboz:session>
 <lomboz:sessionEjb>
 <j2ee:display-name>TeacherS</j2ee:display-name>
 <j2ee:ejb-name>TeacherSEjb</j2ee:ejb-name>
 <j2ee:ejb-class>cn.edu.zucc.research.ejb.session.teacher.TeacherSBean</j2ee:ejb-class>
 <j2ee:session-type>Stateless</j2ee:session-type>
 <j2ee:transaction-type>Container</j2ee:transaction-type>
 </lomboz:sessionEjb>
 </lomboz:session>
 </lomboz:EJB>
 <!-- lomboz.endDefinition -->
 *
 * <!-- begin-xdoclet-definition --> 
 * @ejb.bean name="TeacherS"	
 *           jndi-name="TeacherSEjb"
 *           type="Stateless" 
 *           transaction-type="Container"
 * 
 * <!-- end-xdoclet-definition --> 
 * @generated
 */
public abstract class TeacherSBean implements javax.ejb.SessionBean {
    protected Connection conn = null;
    protected Statement st = null;
       
    private TeacherHome getTeacherHome() throws NamingException {
        return (TeacherHome) getContext().lookup(TeacherHome.JNDI_NAME);
    }

    private InitialContext getContext() throws NamingException {
        Hashtable props = new Hashtable();
        props.put(InitialContext.INITIAL_CONTEXT_FACTORY,
                "org.jnp.interfaces.NamingContextFactory");
        props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");
        InitialContext initialContext = new InitialContext(props);
        return initialContext;
    }
    
    //把传输过来的数据封装成javaBean
    /**
	 * @ejb.interface-method
	 *	view-type="remote" 
	**/
    public TeacherLogin bean(String userId, String userName, String userPass,Date registerDate,
            String newPwd ,String checkPwd ){
        TeacherLogin teacher = new TeacherLogin();
        teacher.setUserId(userId);
        teacher.setUserName(userName);
        teacher.setUserPass(userPass);
        teacher.setCheckpwd(checkPwd);
        teacher.setNewpwd(newPwd);
        return teacher;
   
    }
    
    //核对登入信息
    /**
	 * @ejb.interface-method
	 *	view-type="remote" 
	**/
	public synchronized void checkLogin(TeacherLogin teacher)throws ResearchException {
        try {
            Teacher t = (Teacher)this.getTeacherHome().findByPrimaryKey(teacher.getUserId());
            if(!teacher.getUserPass().equals(t.getUserPass())){
                throw new ResearchException("Password  is wrong !");
            }
            
        }catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (RemoteException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (FinderException e1) {
            throw new ResearchException(teacher.getUserId()+" is not exist!");
        }
	}
	
	//查找用户是否存在 ,存在返回true
	/**
	 * @ejb.interface-method
	 *	view-type="remote" 
	**/
	public synchronized boolean userExist(TeacherLogin teacher){
	    try {
            Teacher t = (Teacher)this.getTeacherHome().findByPrimaryKey(teacher.getUserId());
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FinderException e) {
            return false;
        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
	    return true;
	    
	}
	
	//用户重置密码
	/**
	 * @throws ResearchException
	 * @ejb.interface-method
	 *	view-type="remote" 
	**/
	public synchronized void usersetpwd(TeacherLogin teacher) throws ResearchException{
	    try {
	        if(!teacher.getNewpwd().equals(teacher.getCheckpwd())){
	            throw new ResearchException("The checked password is wrong!");
	        }
            Teacher t = (Teacher)this.getTeacherHome().findByPrimaryKey(teacher.getUserId());
            t.setUserPass(teacher.getCheckpwd());
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FinderException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
	}
	
	//修改密码
	/**
	 * @throws ResearchException
	 * @ejb.interface-method
	 *	view-type="remote" 
	**/
	public synchronized void changePwd(TeacherLogin teacher) throws ResearchException{
	    try {
	        if(teacher.getCheckpwd()==""||teacher.getNewpwd()==""||teacher.getUserPass()==""||
	                teacher.getCheckpwd()==null||teacher.getNewpwd()==null||teacher.getUserPass()==null){
	            throw new ResearchException("some informations are null!");
	        }
	        if(!teacher.getNewpwd().equals(teacher.getCheckpwd())){
	            throw new ResearchException("The checked password is wrong!");
	        }
            Teacher t = (Teacher)this.getTeacherHome().findByPrimaryKey(teacher.getUserId());
            if(!t.getUserPass().equals(teacher.getUserPass())){
                throw new ResearchException("The old password is wrong!");
            }
            t.setUserPass(teacher.getCheckpwd());
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FinderException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
	    
	}
	
	//删除用户信息
	/**
	 * @ejb.interface-method
	 *	view-type="remote" 
	**/
	public synchronized void deleteTeacher(TeacherLogin teacher) {
	    try {
            Teacher t = (Teacher)this.getTeacherHome().findByPrimaryKey(teacher.getUserId());
            t.remove();
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FinderException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (RemoveException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
	    
	}
	
	//批量删除用户信息
	/**
	 * @ejb.interface-method
	 *	view-type="remote" 
	**/
	public synchronized void deleteMoreTeacher(TeacherLogin teacher[]) {
        for(int i=0;i<teacher.length;i++){
            Teacher t;
            try {
                t = (Teacher)this.getTeacherHome().findByPrimaryKey(teacher[i].getUserId());
                t.remove();
            } catch (RemoteException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (FinderException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NamingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (RemoveException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
        }
	}
	
	//初始化密码
	/**
	 * @ejb.interface-method
	 *	view-type="remote" 
	**/
	public  synchronized void initUserPwd(TeacherLogin teacher){	  
	    try {
            Teacher t = (Teacher) this.getTeacherHome().findByPrimaryKey(teacher.getUserId());
            t.setUserPass(t.getUserId());
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FinderException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
	}
	
	//添加用户帐号
	/**
	 * @ejb.interface-method
	 *	view-type="remote" 
	**/
	public  synchronized void addteacher(TeacherLogin teacher){	
	    try {
            this.getTeacherHome().create(teacher.getUserId(),teacher.getUserName(),
                    teacher.getUserPass(),teacher.getRegisterDate());
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (CreateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
	}
}

⌨️ 快捷键说明

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