Prerequisite
The Window®open PERSPECTIVE®OTHER®J2EE perspective is Open. creating the Web Module Project
The Web resources are developed in a Web Project in the Java perspective.
...
1. Choose File®new®project from the main menu.
2. Choose web®dynamic Web Project 2.5 on the NEW Project screen.
3. Choose Next to proceed to the "Create a Dynamic Web 2.5 Project screen."
4. Enter Converterweb in the Project Name field.
5. To assign the WEB project to the previously created Enterprise application project, check ADD project to a EAR an D Select Converterear from the EAR Project Name field.
6. Choose Finish to create your Web ' s project structure. creating a Web Client
The WEB client in this tutorial is a JSP.
...
1. In the Project Explorer choose Converterweb®webcontent.
2. From the context menu of webcontent choose New®other.
3. On the New screen choose Web®jsp.
4. Choose Next.
5. Enter index.jsp in the File Name field.
6. Choose Finish.
7. Implement the JSP as follows:
<%@ page import= "com.sap.tutorial.javaee.ConverterLocal, java.math.*, javax.naming.* "%> <%! Private converterlocal Converterbean = null; Public void Jspinit () { Try { InitialContext IC = new initialcontext (); Converterbean = (converterlocal) Ic.lookup ("Java:comp/env/converter"); catch (Exception ex) { System.out.println ("couldn ' t create converter bean.") + Ex.getmessage ()); } } Public void Jspdestroy () { Converterbean = null; } %> <title>currency converter</title> <body> <p>enter an amount to convert:</p> <form method= "Get" > <input type= "text" name= "Amount" size= ">" <input type= "Submit" value= "Submit" > </form> <% String amount = Request.getparameter ("Amount"); if (Amount!= null && amount.length () > 0) { BigDecimal value = new BigDecimal (amount); BigDecimal Euroamount = Converterbean.dollartoeuro (value); %> <p> <%= amount%> USD are <%= euroamount%> EUR <br> <% BigDecimal Dollaramount = Converterbean.eurotodollar (value); %> <%= amount%> EUR are <%= dollaramount%> USD </p> <% } %> </body> |
8. Save the index.jsp file. Editing The Web.xml deployment descriptor
...
1. Expand the Web-inf folder under WebContent.
2. Double-click on the Web.xml file to open it for editing.
3. Add the following code in the XML source to define a local EJB reference to Converter Bean: