JSP调用EJB3.0实例(Myeclipse2014+Tomcat7+Jboss7).docx_第1页
JSP调用EJB3.0实例(Myeclipse2014+Tomcat7+Jboss7).docx_第2页
JSP调用EJB3.0实例(Myeclipse2014+Tomcat7+Jboss7).docx_第3页
JSP调用EJB3.0实例(Myeclipse2014+Tomcat7+Jboss7).docx_第4页
JSP调用EJB3.0实例(Myeclipse2014+Tomcat7+Jboss7).docx_第5页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

JSP调用EJB3.0实例(Myeclipse2014+Tomcat7+Jboss7)赖东升2014/9/18 第20页目录JSP调用EJB3.0实例1目录21.1修改历史11.2所需软件11.2.1开发工具11.2.2WEB服务器11.2.3EJB服务器11.3实现步骤21.3.1开发EJB工程创建HelloEJB部署HelloEJB测试HelloEJB91.3.2开发WEB工程创建HelloWeb工程客户端测试HelloEJB创建JSP程序部署web程序访问web程序201.4参考文件211.1 修改历史序号修改日期修改人员修改摘要12014/9/18赖东升新建1.2 所需软件1.2.1 开发工具myeclipse-pro-2014.exe /Myeclipse1.2.2 WEB服务器apache-tomcat-7.0.5-windows-x64.zip /Tomcat1.2.3 EJB服务器jboss-as-7.1.1.Final.zip /Jboss1.3 实现步骤1.3.1 开发EJB工程 创建HelloEJB删除ejbmodule目录,新建src目录,并添加JavaEE 6.0类库新建Session BeanHelloWorldLocal.javapackage com;import javax.ejb.Local;Localpublic interface HelloWorldLocal public String SayHello(String name);HelloWorldRemote.javapackage com;import javax.ejb.Remote;Remotepublic interface HelloWorldRemote public String SayHello(String name);HelloWorld.javapackage com;import javax.ejb.Stateless;Statelesspublic class HelloWorld implements HelloWorldLocal, HelloWorldRemote public String SayHello(String name) return name +说:你好,世界!; 文件目录结构:将工程导出成EJB文件 部署HelloEJB部署到Jboss 测试HelloEJB参考web工程1.3.2 开发WEB工程 创建HelloWeb工程 客户端测试HelloEJB将EJB工程中的接口程序HelloWorldRemote.java拷贝过来,并增加类库jboss-client-7.1.1.Final.jar到web工程中, !- jboss4 - !- weblogic10 -文件目录结构:创建客户端测试程序:方法getJboss4()为访问jboss4的代码,需要类库jbossall-client-4.2.2.GA.jar支持方法getJboss7java()为直接访问jboss7的代码方法getJboss7ejb()为通过配置文件访问jboss7的代码,需要在根目录下增加配置文件pertiesClientUtility.javapackage client.test;import java.util.Hashtable;import java.util.Properties;import javax.naming.Context;import javax.naming.InitialContext;import javax.naming.NamingException;import com.HelloWorldRemote;public class ClientUtility public static HelloWorldRemote getJboss4() throws NamingException HelloWorldRemote helloworld = null; Properties props = new Properties(); props.setProperty(java.naming.factory.initial, erfaces.NamingContextFactory); props.setProperty(vider.url, 1:1099);try InitialContext ctx = new InitialContext(props);helloworld = (HelloWorldRemote) ctx.lookup(HelloWorld/remote); catch (NamingException e) System.out.println(e.getMessage();return helloworld; public static HelloWorldRemote getJboss7java() throws NamingException HelloWorldRemote helloworld = null; Properties props = new Properties(); props.put(Context.PROVIDER_URL, remote:/1:4447); props.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory); props.put(Context.SECURITY_PRINCIPAL, System.getProperty(username,jboss); props.put(Context.SECURITY_CREDENTIALS, System.getProperty(password,Pwd_12345678); props.put(jboss.naming.client.ejb.context, true);try InitialContext ctx = new InitialContext(props);String jndi=java:HelloEJB/HelloWorld!com.HelloWorldRemote;System.out.println(-+jndi); helloworld = (HelloWorldRemote) ctx.lookup(jndi); catch (NamingException e) System.out.println(e.getMessage();return helloworld; public static HelloWorldRemote getJboss7ejb() throws NamingException HelloWorldRemote helloworld = null; final Hashtable jndiProperties = new Hashtable(); jndiProperties.put(Context.URL_PKG_PREFIXES, org.jboss.ejb.client.naming); final Context context = new InitialContext(jndiProperties); final String appName = ; final String moduleName = HelloEJB;/工程名 final String distinctName = ; final String beanName = HelloWorld; /HelloWorld.class.getSimpleName(); final String viewClassName = HelloWorldRemote.class.getName(); String jndi=ejb:+appName+/+moduleName+/+ distinctName + /+ beanName + !+viewClassName; System.out.println(-+jndi); helloworld = (HelloWorldRemote) context.lookup(jndi); return helloworld; ClientTest.javapackage client.test;import com.HelloWorldRemote;public class ClientTest public static void main(String args) / TODO Auto-generated method stubHelloWorldRemote helloworld = null; try /helloworld = ClientUtility.getJboss4java(); /System.out.println(helloworld.SayHello(Jboss4); helloworld = ClientUtility.getJboss7java(); System.out.println(helloworld.SayHello(Java); helloworld = ClientUtility.getJboss7ejb(); System.out.println(helloworld.SayHello(EJB); catch (Exception e) e.printStackTrace(); 配置文件=.xnio.Options.SSL_ENABLED=falseremote.connections=default remote.connection.default.host=1remote.connection.default.port = 4447.xnio.Options.SASL_POLICY_NOANONYMOUS=falseremote.connection.default.username=jbossremote.connection.default.password=Pwd_12345678文件目录结构:运行ClientTest测试: 创建J

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论