You implement org.apache.struts.action.Plugin, something like this:
public void init(ActionServlet controller, ModuleConfig config) throws ServletException {
ServletContext app = controller.getServletContext();
app.setAttribute("somePath", getSomePath(controller));
}
. . .
protected String getSomePath(ActionServlet controller) { String somePath = controller.getInitParameter("somePath"); if (somePath == null) somePath = ""; return somePath; }
And register that plugin in struts-config.xml (see docs). When the app initializes, the plugin's init method will be invoked.
Note the difference between the src and page attributes to html:img. Depending on whether your images are in the war (or not as Wendy suggested) you might or might not want the application context to be the prefix of your URLs.
Erik
Gaet wrote:
Thanks very much for your help Erik.
Do I abuse if I ask you your Struts' plugin you are talking about?
TIA
Gaet
----- Original Message ----- From: "Erik Weber" <[EMAIL PROTECTED]> To: "Struts Users Mailing List" <user@struts.apache.org> Sent: Thursday, February 10, 2005 4:02 PM Subject: Re: Handle images path in one place
contains the same images.Using the expression language, you can build paths like this:
<html:img src="${somePath}/images/foo.jpg"/>
The "somePath" variable could be an application scope attribute (ServletContext attribute). I have done this before by writing a (Struts) plugin that gets "somePath" from web.xml (init-param) and stores it as a ServletContext attribute. Then it's availabe (as shown above) in all tags in all your JSPs.
Not sure if there is a better way but that works. You can change your image URL prefix simply by editing web.xml.
Erik
Gaet wrote:
Hello,
I'm writting a web application using J2EE where several pages can
possible into the same place for all images.I would like to have the path to these images into one place an if
only one file to update....For instance in a file and have a tag to access like this <html:img alias="dog">
like this I can move my images from one folder to another, I will have
Does somebody use something similar?
TIA
Gaet
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]