EJB Local接口使用

环境

MyEclipse 8.6 + JBoss 6.0 + JDK 1.6.13 + EJB 3.0

问题

使用EJB Local接口

解决

1. 新建Enterprise Application Project,注意New Web module Project勾选上

2.src--------->新建包

3. 新建接口HelloWorld

package com.wgb.bean;
/** 
 * @className: HelloWorld.java
 * @classDescription: 
 * @function: 
 * @author: Wentasy
 * @createTime: 2012-11-26 下午09:08:14
 * @modifyTime: 
 * @modifyReason: 
 * @since: JDK 1.6
 */
public interface HelloWorld {
	 public String sayHello(String name);
}


4. 新建类 HelloWorldBean

package com.wgb.bean;

import javax.ejb.Local;
//import javax.ejb.Remote;
import javax.ejb.Stateless;

/** 
 * @className: HelloWorldBean.java
 * @classDescription: 
 * @function: 
 * @author: Wentasy
 * @createTime: 2012-11-26 下午09:09:02
 * @modifyTime: 
 * @modifyReason: 
 * @since: JDK 1.6
 */
@Stateless     
//@Remote ({HelloWorld.class})
@Local ({HelloWorld.class})
public class HelloWorldBean {
	public String sayHello(String name) {     
        return  "Hello World!" + name;     
    }    
}


5.WebRoot下修改index.jsp文件

<%@ page language="java" import="java.util.*,javax.naming.*,com.wgb.bean.HelloWorld" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
    
    <%  
     try {  
    	 	//Remote
	    	//Properties props = new Properties();  
	       	//props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");  
	        //props.setProperty("java.naming.provider.url", "localhost:1099");  
	        //props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
      
            //InitialContext ctx = new InitialContext(props);  
            //HelloWorld helloworld = (HelloWorld) ctx.lookup("HelloWorldBean/remote");
            //out.print(helloworld.sayHello("WGB"));  
            
            //Local
            InitialContext ctx = new InitialContext();  
            HelloWorld helloworld = (HelloWorld) ctx.lookup("HelloWorldBean/local");
            out.print(helloworld.sayHello("Wentasy"));
            } catch (NamingException e) {  
                e.printStackTrace();  
            }  
          
     %>  
  </body>
</html>


6. 在浏览器输入http://localhost:8080/HelloEJBWeb访问。

参考资料

深入学习EJB3.0之一:概述与搭建环境

http://blog.csdn.net/drykilllogic/article/details/6185745

ejb jboss myeclipse环境搭建工程实例

http://blog.csdn.net/weirenren_027/article/details/8024060

websphere ejb 远程/本地调用总结

http://lcllcl987.iteye.com/blog/53957

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值