Methods Summary |
---|
protected void | doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
doit(req, resp);
|
protected void | doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
doit(req, resp);
|
protected void | doit(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
int op1 = Integer.parseInt(req.getParameter("op1"));
int op2 = Integer.parseInt(req.getParameter("op2"));
String action = req.getParameter("action");
int result = 0;
if (action.equals("Add"))
result = calculator.add(op1, op2);
else if (action.equals("Subtract")) result = calculator.subtract(op1, op2);
resp.setContentType("text/html");
PrintWriter writer = resp.getWriter();
writer.println("<html>");
writer.println("<body>");
writer.println("<h1>Answer: " + result + "</h1>");
writer.println("</body");
writer.println("</html>");
|
public void | init()Simulate injection of Calculator EJB
super.init();
try
{
InitialContext ctx = new InitialContext();
// J2EE 1.5 has not yet defined exact XML <ejb-ref> syntax for EJB3
CalculatorLocal calculator = (CalculatorLocal) ctx.lookup("tutorial/calculator/local");
setCalculator(calculator);
}
catch (NamingException e)
{
throw new RuntimeException(e);
}
|
public void | setCalculator(org.jboss.tutorial.ear.bean.CalculatorLocal calculator)The @EJB annotation is similated. Tomcat does not yet understand injection annotations.
this.calculator = calculator;
|