String tip = req.getParameter("tip");
String host = req.getParameter("host").trim();
String sPort = req.getParameter("port");
int port = Integer.parseInt(sPort);
int n = Integer.parseInt(sn);
Bernoulli bernoulli = null;
PrintWriter out = res.getWriter();
try {
Interface obj = (Interface)Naming.lookup("//"+host+":"+port+"/Bernoulli");
bernoulli = obj.bernoulli(n);
}
catch (Exception e) {
System.out.println(e.getMessage());
System.exit(1);
}
if (tip.equals("text/html")) {
String title = "Bernoulli Servlet RMI";
res.setContentType("text/html");
out.println("<!DOCTYPE HTML><html><head><title>");
out.println(title);
out.println("</title></head><body>");
out.println("<h1>"+title+"</h1>");
out.println("<p>Bernoulli for N="+n+" is:<br>"+bernoulli.asHtml()+"</p>");
out.println("</body></html>");
} else {
res.setContentType("text/plain");
out.println(bernoulli.asString());
}
out.close();
}