Jiri Chaloupka wrote:

Hallo,
I thinkin how I can read the xml file from /WEB-INF directory.

I found something as InputStream is = servletContext.getResourceAsStream("/WEB-INF/something.xml")

but how I can get servletContext?.

From inside an Action, you can call getServlet().getServletContext().

Or, is t good way to read data, as datasource names, from xml file and store it as instance of config file in session? is there any better way?



It had *better* be a good way to read data, because Struts uses this technique itself to read your struts-config.xml file :-).

A common technique is to read configuration information from a resource like this at the startup time of your web application (in Struts, you could use a PlugIn for this and put the reading code in the init() method). After reading, you would typically store the resulting data into servlet context attributes (also known as application scope) so that they are available to all users. Indeed, this is exactly what Struts does -- for example, the ModuleConfig for the default application module is stored under servlet context attribute key "org.apache.struts.action.Module" (normally referenced by the symbolic constant Globals.MODULE_KEY) so that all parts of Struts have access to it.

Thanks for help,
Jiri




Craig




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to