01: package web;
02:
03: import java.io.IOException;
04: import java.io.PrintWriter;
05: import javax.servlet.ServletException;
06: import javax.servlet.http.*;
07:
08: import org.ozoneDB.ExternalDatabase;
09: import db.Hello;
10:
11: public class HelloServlet extends HttpServlet {
12:
13: private ExternalDatabase db;
14: public Hello hello;
15: String message;
16:
17: public void service(HttpServletRequest request,
18: HttpServletResponse response) throws ServletException,
19: IOException {
20: try {
21: System.out.println("[HelloServlet] connecting to ozone...");
22: db = ExternalDatabase
23: .openDatabase("ozonedb:remote://localhost:3333");
24: System.out.println("[HelloServlet] Connected!");
25: db.reloadClasses();
26: System.out.println("[HelloServlet] Classes reloaded");
27: hello = (Hello) db.objectForName("hej");
28: message = "<html> <head> </head> <body> "
29: + hello.getGreeting() + "</body> </html>";
30: System.out
31: .println("[HelloServlet] Successfully used object");
32: db.close();
33: } catch (Exception e) {
34: System.out.println("[HelloServlet] Can't connect to ozone."
35: + e.toString());
36: message = "<html> <head> </head> <body> " + e.toString()
37: + "</body> </html>";
38: }
39: PrintWriter out = response.getWriter();
40: System.out
41: .println("[HelloServlet] Sending the following resonse back to client: "
42: + message);
43: out.println(message);
44: out.flush();
45: out.close();
46: }
47: }
|