Create j2ee application

Assignment Help Programming Languages
Reference no: EM13962234

Overview
This example creates a session bean that contains business logic to calculate the total amount of money accrued for a savings scheme. This session bean is accessed by an application client and web client (Part i. below). You are then required to add a mobile client (Part ii. below).

Part i. Create J2EE Application
The following steps are followed:

Business-tier components run on the J2EE server.
1. Create session bean to represent business logic - Calculator

Client-tier components run on the client machine.
2. Create an application client to access the Calculator
3. Create JSP web client to access the Calculator

Note: Use simple configuration on local host i.e

Part ii. Mobile Client
Build a mobile client for the calculator.
In your system the server should return a result and the number of calculation requests a user has done in a session. Both the result and the number of calculations should be shown on the client.
Hint: Build the basic system, then add the number of calculations functionality.


For part(ii) document the following:
i. Code of the programs.
ii. Output from a complete execution of the system. (screen short)
iii. Brief explanation of system behaviour with respect to all application components.

 

 

 

 

Details

Part i. Create Enterprise Application(with Application Client) : CalculatorApp

0.File>New Project
1. Select Catorgories:Enterprise, Projects:Enterprise Application

 


2. Next>

3. Add Name:CalculatorApp
4. Select Creat Application Client Module
5. Change Project location to your directories

 


6. To Set Server select Manage...

 

7. Select Add Server .....

8. Next window not shown, but in Select box select: Sun Java System Application Server.
9. Next>


Browse to Platform location


10.Next>

11. Add Password
12. Select Finish until Project created



Create Session Bean to hold Business Logic

13. Right click ejb Project > new > Session Bean
14. Add : name= Calculator; Package=ejb;
15. Select Remote and Local Interfaces > Finish

 



16. Add calculate() method
Right click in code > EJB Methods
Wizard Updates interfaces automatically ( beta version required restart to get this
option to show!)
Add name
Use Add... Button to add methods parameters

 

 

17. Calculate Session Bean code:


package ejb;

import javax.ejb.Stateless;

@Stateless
public class CalculatorBean implements CalculatorRemote, CalculatorLocal {

/** Creates a new instance of CalculatorBean */
public CalculatorBean() {
}

public double calculate(int startAge, int endAge, double growthRate,
double savings) {
double tmp =
Math.pow(1. + growthRate / 12., 12. * (endAge - startAge) + 1);
return savings * 12. * (tmp - 1) / growthRate;
}

}

Create Application Client

18. Navigate to the main.java class in the client project
(see screen shot below)

19. Import bean reference:
right click in code area > Enterprise Resources> Call enterprise bean
Select Referenced Interface: Remote
>o.k



18. Client Class main.java



20. Add access code:
Use Alt-Shift-F to generate any necessary imports.

public static void main(String[] args) {
System.out.println("Data to Calculator Bean ");
System.out.println("int start=25, int end=65,
double growthrate=0.01, double saving=£350 ");
try {

NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);

// Access bean
double d = cal.calculate(25,65,0.01,350);
System.out.println("The balance at the End age is " +
nf.format(d));

} catch (Exception e) {
System.out.println("error in Bean Access");;}

}


Run Application Client

21. Set client type from Application properties:
right click on Application project
select:
properties/run/client module URI
select CalculatorApp-app-clientwar

Uncheck Display Browser on Run

 


Deploy and Run Application

22. Right click on Application > Run Project
Note deployment to server and output.


Create Web Client

23. Navigate to the index.jsp class in the web project
(see screen shot below)


24. Replace index code with:
Note code to obtain session bean reference


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"https://www.w3.org/TR/html4/loose.dtd">

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ page import="ejb.CalculatorLocal, javax.naming.*, java.text.*"%>

<%!
private CalculatorLocal cal = null;
public void jspInit () {
try {
System.out.println("JSP init");
InitialContext ctx = new InitialContext();
cal = (CalculatorLocal)ctx.lookup(
"java:comp/env/local_ref");


} catch (Exception e) {
System.out.println("EJB REFERENCE PROBLEM");
e.printStackTrace ();
}
}


%>


<%
String result;
int start = 25;
int end = 65;
double growthrate = 0.08;
double saving = 300.0;

try {
start = Integer.parseInt(request.getParameter ("start"));
end = Integer.parseInt(request.getParameter ("end"));
growthrate = Double.parseDouble(request.getParameter ("growthrate"));
saving = Double.parseDouble(request.getParameter ("saving"));
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);
result = nf.format(cal.calculate(start, end, growthrate, saving));
} catch (Exception e) {
result = "Please press - Calculate";}
%>

 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>

<body>

<p>Investment calculator2<br/>
<form action="index.jsp" method="post">
Start age = <input type="text" name="start" value="<%=start%>"><br/>
End age = <input type="text" name="end" value="<%=end%>"><br/>
Annual Growth Rate = <input type="text" name="growthrate" value="<%=growthrate%>"><br/>
Montly Saving = <input type="text" name="saving" value="<%=saving%>"><br/>
<input type="submit" value="Calculate">
<INPUT type="button" value="Close Window" onClick="window.close()">
</form>
</p>

<p>The result from the last calculation: The balance at the End age is £
<b><%=result%></b></p>


</body>
</html>
23. Index.jsp

25. Set client to web client
right click on Application project
select:
properties/run/client module URI
select CalculatorApp-war.war
check Display Browser on Run

 


Set bean reference in Descriptor

26. Input references in web.xml as below to set <ejb-local-ref>.
Double click on web.xml
Select References tab
Expand EJB References
Select Add

Deploy and Run Application

27. Right click on Application > Run Project
Note deployment to server and web browser output.
26. Descriptor References

 


Attachment:- Logbook1_Exercise_D_new-1.rar

Reference no: EM13962234

Questions Cloud

Semiconductor manufacturing process : In a semiconductor manufacturing process, three wafers from a lot are tested. Each wafer is classified aspassorfail. Assume that the probability that a wafer passes the test is 0.8 and that wafers are independent.
Approximately half of new technology ventures rely : Approximately half of new technology ventures rely on one customer for at least 50% of first-year sales. Identify at least three issues resulting in overdependence on one customer. Which issue is the most important and what can be done to mitigate th..
Paper about american military power around the globe : Next week, we are going to start on a paper about American military power around the globe. As a lead-up to that, let's consider how WWII helped to shape what has often been called "The American Century."
Minimax regret criterion and equally likely criterion : Shaq Bryant sells newspapers on Sunday mornings in an area surrounded by three busy churches. Assume that Shaq’s demand can either be for 100, 300, or 500 newspapers, depending on traffic and weather. Shaq has the option to order 100, 300, or 500 new..
Create j2ee application : Business-tier components run on the J2EE server. 1. Create session bean to represent business logic - CalculatorClient-tier components run on the client machine. 2. Create an application client to access the Calculator
General administrative expenses are allocated : Given the current level of sales, would you recommend that the model C3 lawn chair be dropped? Prepare appropriate computations to support your answer.
How long will take until the total amount of silver dissolve : How long will it take until the total amount of silver is dissolved? Assume the average density of 8 g/ cm^3 for the alloy sample
Describe the process of decision analysis with probabilities : Describe the process of decision analysis with probabilities. Make sure to talk about the expected value approach, decision trees, sensitivity analysis, and how sample information may be used to revise and improve the decision analysis. Examples?
Write down the gravitational potential energy : The figure shows a child's toy, which has the shape of a cylinder mounted on top of a hemisphere. The radius of the hemisphere is R and the CM of the whole toy is at height h above the floor. Write down the gravitational potential energy when the t..

Reviews

Write a Review

 

Programming Languages Questions & Answers

  Write application to compute and show parking charges

Write down the application which computes and shows parking charges for each customer who parked in garage yesterday. You must enter hours parked for each customer.

  Program to execute on cse unix environment

Your program should be written in C++, execute correctly on CSE unix environment, and compile using g++ compiler using makefile.

  Write program to read line of text which ends with sentinel

Write program which will read line of text which ends with a period, that serves as sentinel value. Display all the letters which occur in text, one per line and in alphabetical order,

  Create an xml document that marks up nutrition facts

Create an XML document that marks up the nutrition facts for a package of Grandma White's cookies. A package of cookies has a serving size of 1 package.

  Write the psuedocode showing the logic for a program

Write the psuedocode showing the logic for a program that allows a user to enter 12 numbers and then displays them in the reverse order of their entry

  Event-driven programming or command line programming

Imagine that you have a choice between using event-driven programming or command line programming to develop a computer program. Determine one (1) advantage and (1) disadvantage of using each. Select the style of programming that you prefer, and j..

  Determine the number of days in the current month

The second should accept two values, determine the modulus and return the value, which the calling statement should then print out.

  Ms word versus other processing program

MS word Versus other processing program

  Explain the functions which are useful

Explain some of the functions which you have found useful, where you found them, and how you use them. Describe good programming practices.

  Program to prompts user for integer and print prime number

Give a program which will compile in VS 2010. Write a program to prompts user for integer and then prints out all prime numbers up to that integer.

  Write a test harness for these classes

Write an interface IClown that defines one method Honk(). Modify the TallGuyClown class to implement that interface so that calling Honk() will display a MessageBox (as above) that says "Honk my horn!". Add a property FunnyThingIHave to the interf..

  What is java adapter class

What is Java adapter class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd