no

Creating Your First Enterprise Application Project on Eclipse

First you should create an ejb project as specified here: http://czetsuya-tech.blogspot.com/2011/03/creating-your-first-ejb3-project-in.htm...

First you should create an ejb project as specified here:
http://czetsuya-tech.blogspot.com/2011/03/creating-your-first-ejb3-project-in.html

Take note that my interface were inside the ejb project. You can pull that out and place in its own project ipielEJB2Client.

Note that I set it up on jboss server.

How to create an EAR project, with EJB, EJB Client and Dynamic web project.

1.) Follow the instruction above
2.) You can extract the interface in an ejbclient. The best way to accomplish his is on creating the ejb project, check the option that says "include client".
Let's name the 2 projects ipielEJB2 aind ipielEJB2Client.
ipielEJB2Client should include jboss-javaee.jar in its build path, which can be found on JBOSS_HOME/common/lib.
3.) Create an EAR project, name it ipielEJB2EAR.
The workspace should look like this:
4.) I assume you followed the instruction in the link above. aside from that we need to do some modifications.
add method: String sayHello(String name); to both BookBeanLocal and BookBeanRemote class.
And of course it's implementation on BookBean.java:
public String sayHello(String name) {
  return getClass().getName() + " says hello to " + name + ".";
}
5.) Create a new Web Dynamic Project, lets name it ipielEJB2Web
6.) Add index.jsp, with the following code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 pageEncoding="ISO-8859-1"%>
<!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>Enterprise Application Development</title>
</head>
<body>
  <form action="${pageContext.request.contextPath}/sayHello">
    <input type="text" name="name" /><input type="submit" value="Submit" />
  </form>
</body>
</html>
7.) Add a new servlet in the same project (ipielEJB2Web) with the following code (it will handle the get request):
package com.kbs;

import java.io.IOException;

import javax.ejb.EJB;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.kbs.BookBeanRemote;

/**
 * Servlet implementation class IpielServlet
 */
public class IpielServlet extends HttpServlet implements Servlet {
 private static final long serialVersionUID = 1L;

 @EJB
 BookBeanRemote remoteBook;

 public IpielServlet() {
  super();
 }

 /**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
  *      response)
  */
 protected void doGet(HttpServletRequest request,
   HttpServletResponse response) throws ServletException, IOException {
  String name = request.getParameter("name");
  if (name == null || name.length() == 0) {
   name = "anonymous";
  }
  response.getWriter().write(remoteBook.sayHello(name));
 }

}
8.) ipielEJB2Web project should look like the following:
9.) Right click ipielEJBEAR project and click properties. Go to references and add click the following projects:
ipielEJB2, ipielEJB2Client, ipielEJB2Web
10.) Right click ipielEJB2Web and select Run on Server. If you don't have a server configure yet, then configure 1. I used jboss5.1 ga.
11.) Make sure to start the server.
12.) Open the following url in your browser: http://localhost:8080/ipielEJB2Web, did you see something like this:

Any question? Feel free to ask :-D

Related

javaee 480247475205654347

Post a Comment Default Comments

1 comment

Anonymous said...

I know your post is couple years old but, what if i want to return a book to the jsp?
Let's say i want to add a method in BookBeanLocal (in the ipielEJB2Client) like:

public Book getBook(...);

Is this possible? I tryed but get error and can't find a solution. Or if i want to pass a Book i just pass a Object type?

Thanks

item