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

📄 sessionbean.java~43~

📁 使用J2EE实现了软件园的下载和上传功能
💻 JAVA~43~
字号:
package software;

import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.CreateException;
import javax.rmi.*;
import javax.naming.*;
import java.util.*;

public class sessionBean implements SessionBean {
    SessionContext sessionContext;
    public void ejbRemove() {
    }

    public void ejbActivate() {
    }

    public void ejbPassivate() {
    }


    public void setSessionContext(SessionContext sessionContext) {
        this.sessionContext = sessionContext;
    }

    public Collection  showResult(String str) {
           Collection c=null;
        try {
                     str="%"+str+"%";
                     Context ic = new InitialContext();
                     Object obj = ic.lookup("softwareRemote");
                     software.softwareRemoteHome home = (software.softwareRemoteHome) javax.rmi.PortableRemoteObject.narrow(obj, software.softwareRemoteHome.class);
                     c=home.findSearch(str);
                   }
                   catch (Exception ex) {
                     ex.printStackTrace();
                   }
          return c;
    }

    public void addSoftware(String id,String infor,String path,String type,String size,String name) {
        try {
    javax.naming.Context ic = new javax.naming.InitialContext();
    Object obj = ic.lookup("softwareRemote");
    software.softwareRemoteHome home = (software.softwareRemoteHome) javax.rmi.PortableRemoteObject.narrow(obj, software.softwareRemoteHome.class);
    software.softwareRemote r = home.create(id, new Integer(0), infor, path, type, size, name);
  }
  catch (Exception ex) {
    ex.printStackTrace();
    System.out.println(ex.getMessage());
  }

    }

    public void addDownloadTime(String id) {
        try {
   javax.naming.Context ic = new javax.naming.InitialContext();
   Object obj = ic.lookup("softwareRemote");
   software.softwareRemoteHome home = (software.softwareRemoteHome) javax.rmi.PortableRemoteObject.narrow(obj, software.softwareRemoteHome.class);
   software.softwareRemote r = home.findByPrimaryKey(id);
   //让得到的主键值为id的软件的下载次数增加1
   r.setSoftwareDownloadTime(new Integer(r.getSoftwareDownloadTime().intValue()+1));
 }
 catch (Exception ex) {
   ex.printStackTrace();
   System.out.println(ex.getMessage());
 }

    }

    public Collection getAll() {
        Collection c=new ArrayList();
        try {
                    Context ic = new InitialContext();
                    Object obj = ic.lookup("softwareRemote");
                    software.softwareRemoteHome home = (software.softwareRemoteHome) javax.rmi.PortableRemoteObject.narrow(obj, software.softwareRemoteHome.class);
                    c=home.findAll();
                  }
                  catch (Exception ex) {
                    ex.printStackTrace();
                  }
         return c;

    }

    public Collection getTypeSoftwares(String str) {
        Collection c=new ArrayList();
         try {
                     Context ic = new InitialContext();
                     Object obj = ic.lookup("softwareRemote");
                     software.softwareRemoteHome home = (software.softwareRemoteHome) javax.rmi.PortableRemoteObject.narrow(obj, software.softwareRemoteHome.class);
                     c=home.getTypeSoftwares(str);
                   }
                   catch (Exception ex) {
                     ex.printStackTrace();
                   }
          return c;

    }

    public void modify(String str, String str2) {
        try {
                      Context ic = new InitialContext();
                      Object obj = ic.lookup("softwareRemote");
                      software.softwareRemoteHome home = (software.softwareRemoteHome) javax.rmi.PortableRemoteObject.narrow(obj, software.softwareRemoteHome.class);
                     software.softwareRemote r = home.findByPrimaryKey(str);
                     r.setSoftwareInfor(str2);
                    }
                    catch (Exception ex) {
                      ex.printStackTrace();
                    }

    }

    public Collection getTypes() {
        Collection c=null;
        try {
                    Context ic = new InitialContext();
                    Object obj = ic.lookup("softwareRemote");
                    software.softwareRemoteHome home = (software.softwareRemoteHome) javax.rmi.PortableRemoteObject.narrow(obj, software.softwareRemoteHome.class);
                     c=home.getTypes();
                  }
                  catch (Exception ex) {
                    ex.printStackTrace();
                  }
      return c;
    }

    public void delete(String str) {
        try {
                    Context ic = new InitialContext();
                    Object obj = ic.lookup("softwareRemote");
                    software.softwareRemoteHome home = (software.softwareRemoteHome) javax.rmi.PortableRemoteObject.narrow(obj, software.softwareRemoteHome.class);
                   software.softwareRemote r = home.findByPrimaryKey(str);
                   r.remove();
                  }
                  catch (Exception ex) {
                    ex.printStackTrace();
                  }

    }

    public Collection login(String name, String pwd) {
         Collection c=null;
        try {
                    Context ic = new InitialContext();
                    Object obj = ic.lookup("usersRemote");
                    software.usersRemoteHome home = (software.usersRemoteHome) PortableRemoteObject.narrow(obj, software.usersRemoteHome.class);
                    c=home.findLogin(name,pwd);
                  }
                  catch (Exception ex) {
                    ex.printStackTrace();
                  }
   return c;
    }

    public void addAdmin(String name, String pwd) {
        try {
               Context ic = new InitialContext();
               Object obj = ic.lookup("usersRemote");
               software.usersRemoteHome home = (software.usersRemoteHome) PortableRemoteObject.narrow(obj, software.usersRemoteHome.class);
               Collection c=home.findAll();
               int i=c.size()+1;
               home.create(new Integer(i),name,pwd);
             }
             catch (Exception ex) {
               ex.printStackTrace();
             }

    }

    public void ejbCreate() throws CreateException {
    }
}

⌨️ 快捷键说明

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