Professional Documents
Culture Documents
ExchangeRate
Objectives
Home page
Result of Exchange
<head>
<title>Online Exchange Rate</title>
10.
</head>
11.
<body>
12.
<h1>Exchange Rates</h1>
13.
<h2>Currency Converter</h2>
14.
<html:form action="Lookup.do">
15.
<table>
16.
<tr>
<%@page contentType="text/html"%>
2.
3.
4.
5.
6.
<html>
<head>
<title>Online Exchange Rates</title>
7.
</head>
8.
<body>
9.
<h1>Exchange Rates</h1>
10.
<h2>Currency Converter</h2><br/><br/>
11.
<table>
12.
13.
<tr>
14.
15.
</tr>
16.
<br/><br/>
LookupForm.java
1.
package com.myapp.struts;
2.
3.
import javax.servlet.http.HttpServletRequest;
4.
import org.apache.struts.action.*;
5.
6.
7.
8.
9.
10.
11.
// set/get methods
12.
13.
symbol=null;
14.
amount=null;
15.
16.
}
}
10
LookupAction.java (1/3)
1.
package com.myapp.struts;
2.
import java.util.Properties;
3.
import javax.servlet.ServletContext;
4.
import javax.servlet.http.*;
5.
import org.apache.struts.action.*;
6.
7.
8.
9.
10.
11.
12.
13.
14.
throws Exception {
15.
String exchRate=null;
16.
String symbol=null;
17.
String amount=null;
LookupAction.java (2/3)
String target=new String("success");
if(form!=null){
LookupForm lookupForm=(LookupForm)form;
symbol=lookupForm.getSymbol();
amount=lookupForm.getAmount();
exchRate=getQuote(symbol, amount);
}
If (exchRate==null) {
target=new String("failure");
} else {
request.setAttribute("EXCHRATE", exchRate);
request.setAttribute("SYMBOL", symbol);
request.setAttribute("PRICE", globalPrice);
request.setAttribute("AMOUNT", amount);
}
return mapping.findForward(target);
}
LookupAction.java (3/3)
protected String getQuote(String symbol, String amount){
ServletContext context=servlet.getServletContext();
Properties prop=(Properties)context.getAttribute("info");
String price=prop.getProperty(symbol);
globalPrice=price;
Float exch=new Float((Float.parseFloat(price))*(Float.parseFloat(amount)));
String exchRate=exch.toString();
return exchRate;
}
String globalPrice=null;
}
10.
public ConverterPlugin() {
11.
12.
13.
14.
throws ServletException{
15.
16.
17.
<struts-config>
2.
<form-beans>
3.
4.
</form-beans>
5.
6.
7.
<action-mappings>
<action path="/Lookup" type="com.myapp.struts.LookupAction"
name="LookupForm">
8.
9.
10.
</action>
11.
12.
scope="session" type="com.myapp.struts.LookupAction"/>
13.
14.
15.
</action-mappings>
...