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中)
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中)
解决方案 »
- String args[]和String[] args有什么区别
- 求CMS(网站内容管理)的电子书或者相关实现教程。
- MyEclipse开发ejb问题,请高手帮忙看一下
- 金币系统需求详解
- Tomcat6.0.18日志过大问题?stdout输出了很多debug信息,log4j也没用?
- com.synchrobit.synchroflow.api.web.*是哪个jar包?
- 如何解决包的版本不兼容问题?
- jsp跳转到下个页面的问题(程序如下)
- 关于action post提交到某一个页面的问题
- java 中堆和堆栈的问题
- EJB 容器 的问题还是 开发使用的问题 ----------- 指教. wait online
- 怎样取得数据库中多条数据?
我不太明白你的问题,能不能讲的具体点
jndi!!!
这个我知道,我已经把bean配置和部署好了,这应该算jndi的配置吧
就是可以使用这个bean了(这里是指完成“登陆”的ejb)
我做的application调用没有任何问题,但是转到applet就是出错
我是在jbuilder6里直接运行的,这样的话如何设置安全级别?这样运行会不会有问题?to wjmmml(笑着悲伤)
程序应该没有逻辑问题,因为我在application中就是这样做的。我查了一下,在运行Context initial = new InitialContext(System.getProperties());时就开始出问题了,即程序死掉。
楼上的兄弟们,指点指点!!
解决这种问题最好的方案是什么啊?大家不妨讨论讨论
permission java.security.AllPermission;
};//(这会打开Applet的全部权限)
试着看行不行!