index.html
<html>
<head>
<title>Currency Converter</title>
</head>
<body>
<form action="CCServlet" >
Enter Amount <input type="text" name="amt"><br>
Select Conversion Type
<input type="radio" name="type" value="r2d" checked>Rupees to Dollar
<input type="radio" name="type" value="d2r" > Dollor to Rupees<br>
<input type="reset" value="Reset" >
<input type="submit" value="CONVERT" >
</form>
</body>
</html>
CCServlet.java
package mypack;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.ejb.EJB;
import mybeans.CCBean;
public class CCServlet extends HttpServlet {
@EJB CCBean obj; public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
double amt = Double.parseDouble(request.getParameter("amt")); if(request.getParameter("type").equals("r2d"))
{
out.println("<h1>"+amt+ " Rupees = "+obj.r2Dollor(amt)+" Dollors</h1>");
}
if(request.getParameter("type").equals("d2r"))
{
out.println("<h1>"+amt+ " Dollors = "+obj.d2Rupees(amt)+" Rupees</h1>");
}
}
}
CCbean.java
package mybeans;
import javax.ejb.Stateless;
@Stateless public class CCBean {
public CCBean()
{
}
public double r2Dollor(double r)
{
return r/65.65;
}
public double d2Rupees(double d)
{
return d*65.65;
}
}
0 Comments