My first EJB example
来源:互联网 发布:浅析网络舆论监督 编辑:程序博客网 时间:2024/06/03 12:27
1. Download JBoss (I used 1.4.2.2) and configure the environment variable in the computer
2.
(Note: Please tick the ejb-jar.xml generator checkbox):
Right click ejbModule and create the session bean:
Define HelloWorldRemote interface as below:
@Remote
public interface HelloWorldRemote {
public int ejbCalculate(int input);
}
Implement it in HelloWorld:
@Override
public int ejbCalculate(int input) {
return 2 + input;
}
3. Export EJB jar
:
Deploy the EJB jar
Copy the jar into server/default/deploy folder,Start JBOSS,When you see below, it means the deployment is successful。
5. Create client web application to to invoke the EJB
Create a new Dynamic Web Applilcation, and create a test.jsp under WebContent
test.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="com.zou.*, javax.naming.*, java.util.Properties" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<hr>
<center>Hello World</center>
<hr>
<%
Properties props = new Properties();
props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url", "localhost:1099");
try {
InitialContext ctx = new InitialContext(props);
HelloWorldRemote testbean = (HelloWorldRemote)ctx.lookup("HelloWorld/remote");
int first = testbean.ejbCalculate(3);
int second = testbean.ejbCalculate(3);
StringBuffer sb = new StringBuffer();
sb.append("Value:").append(first).append("/").append(second);
out.println(sb.toString());
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
%>
</body>
</html>
, Then export this project as war, and deploy it in the JBoss, then test it.(For this webapp, it should have same session bean structure like EJB prject, copy them into this project, same package name etc.)_
- My first EJB example
- Struts2.0: My First Example
- EJB入门--First EJB
- My first
- MY FIRST
- my first
- my First
- My First !
- MY FIRST
- My First
- MY First
- My First
- my first
- my first
- My First
- my first。。
- my first
- My First
- 获取视频长度
- Android中的延迟加载系列4(ImageView)
- 工程师 or 精英,犹豫中
- 常见手机操作系统列表
- Jenkins邮件通知设置
- My first EJB example
- 使用email-ext替换Jenkins(Hudson)的默认邮件通知
- [HowTo] OpenWRT on x86 PC
- unresolved external symbol __imp__WSAStartup@8 解决方法
- 消息队列
- S3C6410裸机SD卡驱动(SDIO模式)
- DIV+CSS 斜线效果
- win7上安装了ubuntu真机之后,删除ubuntu
- _beginThreadex创建多线程解读