100分相送(EJB问题) 我的开发环境:jbuilderX,WebLogic 8 Win2000 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 请各位帮我看看程序:bean类: ejb1.java: package aejb; import javax.ejb.EJBObject; import java.rmi.*; public interface ejb1 extends EJBObject { public String getName() throws RemoteException; } ejb1Home.java: package aejb; import javax.ejb.EJBHome; import javax.ejb.CreateException; import java.rmi.RemoteException; public interface ejb1Home extends EJBHome { public ejb1 create() throws CreateException, RemoteException; } ejb1Bean.java: package aejb; import javax.ejb.SessionBean; import javax.ejb.SessionContext; import javax.ejb.CreateException; public class ejb1Bean implements SessionBean { SessionContext sessionContext; public void ejbRemove() {} public void ejbActivate() {} public void ejbPassivate() {} public void setSessionContext(SessionContext sessionContext) { this.sessionContext = sessionContext; } public String getName() { return "Hello World"; } public void ejbCreate() throws CreateException { }}打包成EJBModule1.jar其中weblogic-ejb-jar:<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE weblogic-ejb-jar PUBLIC "-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN" "http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd"><weblogic-ejb-jar> <weblogic-enterprise-bean> <ejb-name>ejb1</ejb-name> <jndi-name>ejb1</jndi-name> </weblogic-enterprise-bean></weblogic-ejb-jar>然后把EJBModule1.jar部署到weblogic8applet客户端:package aejb;import java.awt.*;import java.awt.event.*;import java.applet.*;import javax.naming.*;import javax.rmi.PortableRemoteObject;import java.util.*;import javax.swing.*;public class applet extends Applet { private boolean isStandalone = false; String var0; BorderLayout borderLayout1 = new BorderLayout(); Panel UpperPanel = new Panel(); Panel LowerPanel = new Panel(); Panel panel1 = new Panel(); CardLayout cardLayout1 = new CardLayout(); Panel panel2 = new Panel(); BorderLayout borderLayout2 = new BorderLayout(); BorderLayout borderLayout3 = new BorderLayout(); Choice choice1 = new Choice(); Label label1 = new Label(); Label label2 = new Label(); Label label3 = new Label(); CheckboxGroup checkboxGroup1 = new CheckboxGroup(); ejb1Home home; ejb1 ejb; String err=null; //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 applet() { } //Initialize the applet public void init() { try { var0 = this.getParameter("param0", ""); } catch(Exception e) { e.printStackTrace(); } try { jbInit(); } catch(Exception e) { err=e.toString(); } if(err!=null){ Label a=new Label(err); UpperPanel.add(a, null); } } private Context InitialContext() throws Exception { String url = "t3://localhost:7001"; String user = "weblogic"; String password = "12345678"; Properties properties = null; try { properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); properties.put(Context.PROVIDER_URL, url); if (user != null) { properties.put(Context.SECURITY_PRINCIPAL, user); properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password); } return new InitialContext(properties); } catch(Exception e) { throw e; } } //Component initialization private void jbInit() throws Exception { this.setLayout(borderLayout1); choice1.addItem("EngLish"); choice1.addItem("Chinese"); choice1.addItem("ejb"); UpperPanel.setBackground(Color.cyan); LowerPanel.setBackground(Color.pink); LowerPanel.setLayout(cardLayout1); panel2.setLayout(borderLayout2); panel1.setLayout(borderLayout3); panel1.setBackground(Color.white); panel1.setLocale(java.util.Locale.getDefault()); panel2.setBackground(Color.pink); label1.setFont(new java.awt.Font("Dialog", 0, 20)); label1.setText("Select a language"); label2.setAlignment(Label.CENTER); label2.setFont(new java.awt.Font("Dialog", 0, 24)); label2.setLocale(java.util.Locale.getDefault()); label2.setText("晚安!"); label3.setAlignment(Label.CENTER); label3.setFont(new java.awt.Font("Dialog", 0, 24)); label3.setForeground(Color.green); label3.setText("Good Evening"); choice1.addItemListener(new HelloApplet_choice1_itemAdapter(this)); this.add(UpperPanel, BorderLayout.NORTH); UpperPanel.add(label1, null); UpperPanel.add(choice1, null); this.add(LowerPanel, BorderLayout.CENTER); LowerPanel.add(panel1, "panel1"); panel1.add(label3, BorderLayout.CENTER); LowerPanel.add(panel2, "panel2"); panel2.add(label2, BorderLayout.CENTER); } //Start the applet public void start() { } //Stop the applet public void stop() { } //Destroy the applet public void destroy() { } //Get Applet information public String getAppletInfo() { return "Applet Information"; } //Get parameter info public String[][] getParameterInfo() { String[][] pinfo = { {"param0", "String", ""}, }; return pinfo; } void choice1_itemStateChanged(ItemEvent e) { if("EngLish".equals(choice1.getSelectedItem())){ cardLayout1.show(LowerPanel,"panel1"); } else if("Chinese".equals(choice1.getSelectedItem())) {cardLayout1.show(LowerPanel,"panel2");} else{ try{ String name=""; Context context=InitialContext(); Object obj=context.lookup("ejb1"); home=(ejb1Home)PortableRemoteObject.narrow(obj,ejb1Home.class); if(obj==null)name="obj is null"; if(home==null)name="home is null"; ejb=home.create(); if(ejb==null)name="ejb is null"; name=ejb.getName(); JOptionPane.showMessageDialog(null,name); if(name==null||name=="")name="null"; Label lab=new Label(name); Panel p=new Panel(); p.add(lab); LowerPanel.add(p,"ejb"); cardLayout1.show(LowerPanel,"ejb"); }catch(Exception evt){ String err=evt.toString(); String er=""; while(err.length()>0){ if(err.length()>30){er=er+err.substring(0,30)+"\n";err=err.substring(30);} else{er+=err;err="";} } TextArea text=new TextArea(10,35); text.setText(er); Panel p=new Panel(); p.add(text); LowerPanel.add(p,"ejb"); cardLayout1.show(LowerPanel,"ejb"); } } }}class HelloApplet_choice1_itemAdapter implements java.awt.event.ItemListener { applet adaptee; HelloApplet_choice1_itemAdapter(applet adaptee) { this.adaptee = adaptee; } public void itemStateChanged(ItemEvent e) { adaptee.choice1_itemStateChanged(e); }}然后把applet.class,ejb1.class,ejb1Home.class,weblogic.jndi.WLInitialContextFactory.class打包成applet.jarapplet.html:<html><head><meta http-equiv="Content-Type" content="text/html; charset=GB2312"><title>HTML Test Page</title></head><body>aejb.applet will appear below in a Java enabled browser.<br><applet codebase = "." code = "aejb.applet.class" archive="applet.jar" name = "TestApplet" width = "400" height = "300" hspace = "0" vspace = "0" align = "middle"></applet></body></html>打开applet.html网页单击其中下拉框,本来要远程调用,却一点反应都没有,也没有出错信息,请各位批评指正,不胜感激 nutch抓取网站不时的会出现FileAlreadyExistsException 网页间共享cookie的问题(java) 请问一个struts2的ongl的问题, 下载文件不用response 还可以用什么做? MyEclipse 如何连接SqlServer2008? 如何设计webservice接口供客户端使用? Struts2中使用XML如何校验地址栏中的参数? wyy_9715072,接分! 请各位大虾帮我解答,急!!!!!!! fmt 应用 ^_^给大家介绍个j2ee快速开发工具 ^_^ struts,spring,hibernate是什么东东啊
bean类:
ejb1.java:
package aejb;
import javax.ejb.EJBObject;
import java.rmi.*;
public interface ejb1
extends EJBObject {
public String getName() throws RemoteException;
} ejb1Home.java:
package aejb;
import javax.ejb.EJBHome;
import javax.ejb.CreateException;
import java.rmi.RemoteException;
public interface ejb1Home
extends EJBHome {
public ejb1 create() throws CreateException, RemoteException;
} ejb1Bean.java:
package aejb;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.CreateException;
public class ejb1Bean
implements SessionBean {
SessionContext sessionContext; public void ejbRemove() {} public void ejbActivate() {} public void ejbPassivate() {} public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
} public String getName() {
return "Hello World";
} public void ejbCreate() throws CreateException {
}
}
打包成EJBModule1.jar
其中weblogic-ejb-jar:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC "-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN" "http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd">
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>ejb1</ejb-name>
<jndi-name>ejb1</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
然后把EJBModule1.jar部署到weblogic8applet客户端:
package aejb;import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.util.*;
import javax.swing.*;public class applet extends Applet {
private boolean isStandalone = false;
String var0;
BorderLayout borderLayout1 = new BorderLayout();
Panel UpperPanel = new Panel();
Panel LowerPanel = new Panel();
Panel panel1 = new Panel();
CardLayout cardLayout1 = new CardLayout();
Panel panel2 = new Panel();
BorderLayout borderLayout2 = new BorderLayout();
BorderLayout borderLayout3 = new BorderLayout();
Choice choice1 = new Choice();
Label label1 = new Label();
Label label2 = new Label();
Label label3 = new Label();
CheckboxGroup checkboxGroup1 = new CheckboxGroup();
ejb1Home home;
ejb1 ejb;
String err=null; //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 applet() {
} //Initialize the applet
public void init() {
try {
var0 = this.getParameter("param0", "");
}
catch(Exception e) {
e.printStackTrace();
}
try {
jbInit();
}
catch(Exception e) {
err=e.toString();
}
if(err!=null){
Label a=new Label(err);
UpperPanel.add(a, null);
}
}
private Context InitialContext() throws Exception {
String url = "t3://localhost:7001";
String user = "weblogic";
String password = "12345678";
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
} return new InitialContext(properties);
}
catch(Exception e) {
throw e;
}
} //Component initialization
private void jbInit() throws Exception {
this.setLayout(borderLayout1);
choice1.addItem("EngLish");
choice1.addItem("Chinese");
choice1.addItem("ejb");
UpperPanel.setBackground(Color.cyan);
LowerPanel.setBackground(Color.pink);
LowerPanel.setLayout(cardLayout1);
panel2.setLayout(borderLayout2);
panel1.setLayout(borderLayout3);
panel1.setBackground(Color.white);
panel1.setLocale(java.util.Locale.getDefault());
panel2.setBackground(Color.pink);
label1.setFont(new java.awt.Font("Dialog", 0, 20));
label1.setText("Select a language");
label2.setAlignment(Label.CENTER);
label2.setFont(new java.awt.Font("Dialog", 0, 24));
label2.setLocale(java.util.Locale.getDefault());
label2.setText("晚安!");
label3.setAlignment(Label.CENTER);
label3.setFont(new java.awt.Font("Dialog", 0, 24));
label3.setForeground(Color.green);
label3.setText("Good Evening"); choice1.addItemListener(new HelloApplet_choice1_itemAdapter(this)); this.add(UpperPanel, BorderLayout.NORTH);
UpperPanel.add(label1, null);
UpperPanel.add(choice1, null);
this.add(LowerPanel, BorderLayout.CENTER);
LowerPanel.add(panel1, "panel1");
panel1.add(label3, BorderLayout.CENTER);
LowerPanel.add(panel2, "panel2");
panel2.add(label2, BorderLayout.CENTER); } //Start the applet
public void start() {
} //Stop the applet
public void stop() {
} //Destroy the applet
public void destroy() {
} //Get Applet information
public String getAppletInfo() {
return "Applet Information";
} //Get parameter info
public String[][] getParameterInfo() {
String[][] pinfo =
{
{"param0", "String", ""},
};
return pinfo;
} void choice1_itemStateChanged(ItemEvent e) {
if("EngLish".equals(choice1.getSelectedItem())){
cardLayout1.show(LowerPanel,"panel1");
}
else if("Chinese".equals(choice1.getSelectedItem()))
{cardLayout1.show(LowerPanel,"panel2");}
else{
try{
String name="";
Context context=InitialContext();
Object obj=context.lookup("ejb1");
home=(ejb1Home)PortableRemoteObject.narrow(obj,ejb1Home.class);
if(obj==null)name="obj is null";
if(home==null)name="home is null";
ejb=home.create();
if(ejb==null)name="ejb is null";
name=ejb.getName();
JOptionPane.showMessageDialog(null,name);
if(name==null||name=="")name="null";
Label lab=new Label(name);
Panel p=new Panel();
p.add(lab);
LowerPanel.add(p,"ejb");
cardLayout1.show(LowerPanel,"ejb");
}catch(Exception evt){
String err=evt.toString();
String er="";
while(err.length()>0){
if(err.length()>30){er=er+err.substring(0,30)+"\n";err=err.substring(30);}
else{er+=err;err="";}
}
TextArea text=new TextArea(10,35);
text.setText(er);
Panel p=new Panel();
p.add(text);
LowerPanel.add(p,"ejb");
cardLayout1.show(LowerPanel,"ejb"); }
}
}
}class HelloApplet_choice1_itemAdapter implements java.awt.event.ItemListener {
applet adaptee; HelloApplet_choice1_itemAdapter(applet adaptee) {
this.adaptee = adaptee;
}
public void itemStateChanged(ItemEvent e) {
adaptee.choice1_itemStateChanged(e);
}
}
然后把applet.class,ejb1.class,ejb1Home.class,weblogic.jndi.WLInitialContextFactory.class打包成applet.jarapplet.html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>
HTML Test Page
</title>
</head>
<body>
aejb.applet will appear below in a Java enabled browser.<br>
<applet
codebase = "."
code = "aejb.applet.class"
archive="applet.jar"
name = "TestApplet"
width = "400"
height = "300"
hspace = "0"
vspace = "0"
align = "middle"
>
</applet>
</body>
</html>打开applet.html网页
单击其中下拉框,本来要远程调用,却一点反应都没有,也没有出错信息,请各位批评指正,不胜感激