![]() |
![]() |
![]() |
![]() |
![]() |
![]() ![]() |
![]() |
![]() |
![]() ![]() |
![]() |
![]() |
![]() ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
||||||||||||||
![]() ![]() |
![]() |
![]() ![]() |
![]() |
![]() ![]() |
||||||||||||||
![]() ![]() |
![]() ![]() |
![]() ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|||||||||||
![]() |
![]() |
![]() ![]() |
![]() |
![]() ![]() |
![]() |
![]() ![]() |
![]() ![]() ![]() ![]() |
![]() |
![]() |
To create a session EJB you must:
To create a valid session EJB:
NOTE: You must create your EJB within a Package in order to properly deploy it to the iPlanet Application Server. |
NOTE: If you have existing Java object files you wish to add to this EJB you can specify them by selecting the Modify button and navigate to the existing Java object file. |
Four new nodes appear under the salesTax node.
Name calculateTax
Return Type double
Method Parameters Select the Add button to display the Enter
Method Parameter dialog.
NOTE: When entering Java classes as return types, you must specify the fully qualified class name. For example, if the return type is "String" then you must identify the Java class as (java.lang.String). |
The Bean class and the Remote Interface class are modified accordingly.
To view the new business methods, double click on the Sales and SalesEJB Bean Class Java files.
Use the iPlanet AS tab to define iPlanet Application Server specific information for this session Enterprise Java Bean.
Use the Properties and References tabs to edit J2EE standard meta data for this session Enterprise Java Bean.
A compile error appears in the Output Window and in the status bar since you added a business method, but did not identify a return statement.
The Source Editor displays with the error location highlighted in green.
This time the compile should complete without any error messages. Look for a finished message in the status bar.
You now have a valid session EJB and are ready to create the EJB module.
For more information on setting up the security roles see the iPlanet Application Server Integration Module online help Using Advanced Features section.
You can export this EJB module (EJB jar file) or deploy this EJB module to the iPlanet Application Server. However, for purposes of this tutorial, you will deploy this EJB module as part of J2EE application.
You are now ready to create a servlet that accesses this EJB module.
import javax.ejb.*; import javax.naming.*;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Input</title>"); out.println("</head>"); out.println("<body>"); out.println("<form method=post action=\"/NASApp/SalesClient/Calculator\">"); out.println("<h1>California sales tax calculator</h1>"); out.println("Amount of sale is <input type=input name=newVal>"); out.println("<input type=submit value=Submit name=submitButton>"); out.println("</body>"); out.println("</html>"); } /** Handles the HTTP <code>POST</code> method. * @param request servlet request * @param response servlet response */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { String newVal = "0"; String vals[] = request.getParameterValues("newVal"); if (vals != null && vals.length > 0) { newVal = vals[0]; } Double salesAmount = new Double(newVal); response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Output</title>"); out.println("</head>"); out.println("<body>"); try { java.util.Properties p = new java.util.Properties(); Context ctx = new InitialContext(p); Object beanObject=ctx.lookup("java:comp/env/Sales"); salesTax.SalesHome home = (salesTax.SalesHome) beanObject; salesTax.Sales remote = (salesTax.Sales) home.create(); double result = remote.calculateTax(salesAmount.doubleValue()); out.println("<h1>The sales tax on "+salesAmount+" is "+result+"</h1>"); } catch (Exception ex) { out.println("<pre>"); out.println("<h1>Error</h1>"); ex.printStackTrace(out); out.println("</pre>"); } out.println("</body>"); out.println("</html>"); }
Servlet Name Calculator
Display Name Calculator
Servlet ClasstaxApp.Calculator
Servlet Name Calculator
URL Pattern /Calculator
Reference Name: Sales
Description: Sales Tax Calculator
Referenced EJB Name: Sales
Type: Session
Home Interface: salesTax.SalesHome
Remote Interface: salesTax.Sales
The EJB Reference Property Editor now appears with the edits you just made as follows:
The Progress Monitor dialog is displayed. It will disappear when
the deployment process is finished.
The Web Browser launches and displays the following screen.
The browser displays the result.
The next step in the iPlanet Application Server Integration Module Tutorial is creating a container managed persistence Enterprise JavaBean.
![]() |
|||||||||||
![]() |
![]() |
© 2002 Sun Microsystems, Inc. | ![]() |
![]() |
![]() |
terms of use privacy policy feedback | ![]() |
![]() |
![]() |
![]() |