import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;
import javax.swing.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import Login;
import LoginHome;/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: </p>
 * @author unascribed
 * @version 1.0
 */public class login extends Applet {
  boolean isStandalone = false;  //my variables
  GridBagLayout gridBagLayout1 = new GridBagLayout();
  JButton btnLogin = new JButton();
  JButton btnQuit = new JButton();
  JLabel lblUserName = new JLabel();
  JTextField txtUserName = new JTextField();
  JLabel lblPassword = new JLabel();
  JPasswordField txtPassword = new JPasswordField();  //Get a parameter value
  public String getParameter(String key, String def) {
    return isStandalone ? System.getProperty(key, def) :
      (getParameter(key) != null ? getParameter(key) : def);
  }  //Construct the applet
  public login() {
  }
  //Initialize the applet
  public void init() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }  }
  //Component initialization
  private void jbInit() throws Exception {
    this.setLayout(gridBagLayout1);
    btnLogin.setText("登录");
    btnLogin.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        btnLogin_actionPerformed(e);
      }
    });
    btnQuit.setText("退出");
    btnQuit.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
         setVisible(false);
      }
    });    lblPassword.setText("密码:");
    lblUserName.setText("用户名:");    this.add(lblUserName,  new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(15, 0, 6, 30), 5, 5));
    this.add(txtUserName,  new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0
            ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(7, 2, 6, 0), 120, 0));    this.add(lblPassword,  new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(10, 0, 13, 38), 0, 0));
    this.add(txtPassword,  new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 0, 9, 0), 120, 0));    this.add(btnLogin,  new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
            ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(9, 17, 9, 19), 28, 0));
    this.add(btnQuit,  new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
            ,GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(10, 18, 12, 16), 32, 0));
  }
  //Get Applet information
  public String getAppletInfo() {
    return "Applet Information";
  }
  //Get parameter info
  public String[][] getParameterInfo() {
    return null;
  }  void btnLogin_actionPerformed(ActionEvent e) {
    String strUserName="", strPassword="";
    strUserName = txtUserName.getText().trim();
    strPassword=String.valueOf(txtPassword.getPassword());
    JOptionPane.showMessageDialog(null,strUserName);    try{
         Context initial = new InitialContext(System.getProperties());
         LoginHome home = (LoginHome)initial.lookup("MyLogin");
         Login LoginObj = home.create();
         int userid =0;
         userid = LoginObj.Check(strUserName,strPassword);
         JOptionPane.showMessageDialog(null,"qq!");
         if(userid>0)
         {
             //LoginObj.setInitState(userid);
             JOptionPane.showMessageDialog(null,"欢迎您使用本系统!");
         }
         else //if(userid==0)
         {
             JOptionPane.showMessageDialog(null,"登录失败,请重试!");
             txtUserName.setText("");
             txtPassword.setText("");
         }        }catch(Exception ex){
               System.err.println("Caught an unexpected exception");
               ex.printStackTrace();
         }
  }}目的就是调用ejb(用于检查登陆名称和密码是否正确,数据库的连接都在ejb中)

解决方案 »

  1.   

    你用ie的那台机器有jndi的配置么?
      

  2.   

    to SAsura
    我不太明白你的问题,能不能讲的具体点
      

  3.   

    LoginHome home = (LoginHome)initial.lookup("MyLogin");
    jndi!!!
      

  4.   

    to xuancao(飞云)
    这个我知道,我已经把bean配置和部署好了,这应该算jndi的配置吧
      

  5.   

    程序好像没有问题,应该是你的配置问题你把bean配置和部署好了,是一个什么概念?
      

  6.   

    to haode(好的)
    就是可以使用这个bean了(这里是指完成“登陆”的ejb)
    我做的application调用没有任何问题,但是转到applet就是出错
      

  7.   

    IE 的安全限制, 由于Applet 时在客户端执行的,考虑到用户安全的问题,Applet 的访问权限非常的低,请试着把Internet安全级别设到最低,看看成不成。
      

  8.   

    to Donsun(立冬)
    我是在jbuilder6里直接运行的,这样的话如何设置安全级别?这样运行会不会有问题?to  wjmmml(笑着悲伤)
    程序应该没有逻辑问题,因为我在application中就是这样做的。我查了一下,在运行Context initial = new InitialContext(System.getProperties());时就开始出问题了,即程序死掉。
      

  9.   

    你确认Applet 肯定能调用EJB吗?换一个办法吧!比如Socket 或者是RMI 之类的间接调用。
      

  10.   

    applet 不能直接访问 EJB.
      

  11.   

    那applet怎样才能更好地访问ejb呢?通过servlet?
    楼上的兄弟们,指点指点!!
    解决这种问题最好的方案是什么啊?大家不妨讨论讨论
      

  12.   

    错,APPLET能直接访问EJB,我用POWERJ做了一个EJB(hh/bean:hh是包的名字,BEAN的名字是bean),是用来连接数据库的,然后做了一个APPLET,APPLET里放了一个EJB,然后在POWERJ里运行成功,可以从数据库中取出数据,但是把APPLET放到IE上就出现不能找到包hh/bean,各位帮忙看看是怎么回事。
      

  13.   

    搜索java.policy文件在其中加上grant{
    permission java.security.AllPermission;
    };//(这会打开Applet的全部权限)
    试着看行不行!