IT Mill, getServletContext()

Good morning,

I would like to run the objectdatase db4o with IT Mill. Therefore I’ve configured the web.xml and added a listener to tomcat (5.5). Goal is, to open and close the database with tomcat.

The db4o tutorial says, that the following code will connect to the database.

ServletContext context = getServletContext();
ObjectServer server= (ObjectServer) context.getAttribute("db4oServer");
database = server.openClient();

Problem is, the example runs in a class witch extends from HttpServlet. In my init() function of the ITMill-Application-Class, I don’t have access to the getServletContext() Method… do you have idea to get this example running?

Thanks in advance,
Best regards




Just a breakdown of the previous posters suggestion, in case it makes things clearer:

ApplicationContext ctx = getContext();
WebApplicationContext webCtx = (WebApplicationContext) ctx;
ServletContext sc = webCtx.getHttpSession().getServletContext();

Ah, i see. Thank you very much!

Best Regards,

Hey there,

this time I would like to open a PDF as MIME Type in the browser. But I’m not getting the ServletOutputStream… ServletOutputStream out = res.getOutputStream();

:?: Thanks in advance,
Best regards

There are many ways to do this, for example if you would like to open PDF in a new window, just do:

   new FileResource(myPdfFile, myApp), 

for more resource-types.

Easier as expected :thumbup: Thank you very much!!

Best Regards,