RSS

Stateless Bean based on Local Interface

05 Mar

HelloEJBLocal.java

package com.xavier.ejb3.sessionbean;

public interface HelloEJBLocal {

        public String hello(String name);

}

HelloEJBBean.java

package com.xavier.ejb3.sessionbean;

import javax.ejb.Local;

import javax.ejb.Stateless;

 

@Stateless

@Local(HelloEJBLocal.class)

public class HelloEJBBean implements HelloEJBLocal {

    public String hello(String name) {

return new String(“Hello “ + name);

    }

}

HelloEJBLocal.jsp

<%@ page language=“java” contentType=“text/html; charset=UTF-8”

pageEncoding=“UTF-8”%>

<%@ page

import=javax.naming.*,com.xavier.ejb3.sessionbean.*,com.xavier.ejb3.entitybean.*,java.util.*”%>

<!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=UTF-8”>

<title>Hello EJB Local Bean</title>

</head>

<body>

<%

try {

final Hashtable jndiProperties = new Hashtable();

jndiProperties.put(Context.PROVIDER_URL, “localhost:1099”);

jndiProperties.put(Context.URL_PKG_PREFIXES,

“org.jboss.ejb.client.naming”);

Context ctx = new InitialContext(jndiProperties);

HelloEJBLocal hr = (HelloEJBLocal) ctx

.lookup(“ejb:ejb3/ejb3//HelloEJBBean!com.xavier.ejb3.sessionbean.HelloEJBLocal”);

out.println(“<br>Invoke EJB via Local Interface<br>”

+ hr.hello(“Xavier”));

} catch (Exception e) {

out.println(“<br>Invoke Local Interface failed.”);

}

%>

</body>

</html>

Advertisements
 
Leave a comment

Posted by on 03/05/2012 in EJB

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: