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 a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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