Re: Handle images path in one place
Neil Aggarwal wrote: Graham: I don't like depending on JavaScript for this. I think your modification to html:base would be perfect. I have voted for it. Thanks. G. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Handle images path in one place
Graham: I don't like depending on JavaScript for this. I think your modification to html:base would be perfect. I have voted for it. Thanks, Neil -- Neil Aggarwal, JAMM Consulting, (972)612-6056, www.JAMMConsulting.com FREE! Valuable info on how your business can reduce operating costs by 17% or more in 6 months or less! http://newsletter.JAMMConsulting.com > -Original Message- > From: news [mailto:[EMAIL PROTECTED] On Behalf Of Graham Reeds > Sent: Monday, February 14, 2005 10:37 PM > To: user@struts.apache.org > Subject: Re: Handle images path in one place > > > I do this in a different way to everyone else:-) > > I use this piece of JavaScript in the of every jsp file: > > if (window.location.href.indexOf("localhost") >= 1) > { document.write('http://localhost/mysite/"; />'); } > else > { document.write('http://www.mysite.com/"; />'); } > > Which writes in the tag for the sole purpose of > accessing images > via id's. I made an enhancement request in bugzilla which > you can vote > on *hint* > (http://issues.apache.org/bugzilla/show_bug.cgi?id=33426) to > make a change to the tag to allow it to take the place of > this javascript. > > Thanks, G. > > > - > 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]
Re: Handle images path in one place
I do this in a different way to everyone else:-) I use this piece of JavaScript in the of every jsp file: if (window.location.href.indexOf("localhost") >= 1) { document.write('http://localhost/mysite/"; />'); } else { document.write('http://www.mysite.com/"; />'); } Which writes in the tag for the sole purpose of accessing images via id's. I made an enhancement request in bugzilla which you can vote on *hint* (http://issues.apache.org/bugzilla/show_bug.cgi?id=33426) to make a change to the tag to allow it to take the place of this javascript. Thanks, G. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Handle images path in one place
Craig: I tried this and it worked flawlessly. Thank you for the info. Thanks, Neil -- Neil Aggarwal, JAMM Consulting, (972)612-6056, www.JAMMConsulting.com FREE! Valuable info on how your business can reduce operating costs by 17% or more in 6 months or less! http://newsletter.JAMMConsulting.com > -Original Message- > From: Craig McClanahan [mailto:[EMAIL PROTECTED] > Sent: Thursday, February 10, 2005 10:22 PM > To: Struts Users Mailing List > Subject: Re: Handle images path in one place > > > On Thu, 10 Feb 2005 23:09:51 -0500, Erik Weber > <[EMAIL PROTECTED]> wrote: > > Sorry, I was using the html-el tag, not the html tag: > > > > > > > > I think you should be able to do what you want without the > el tags if > > you are using JSP 2.0, but to be honest, someone else needs > to jump in > > and bail me out here on that. I think it's a configuration > problem. (web > > app 2.3 v 2.4 or something?) > > You are definitely on the right track. > > If you are using a Servlet 2.4/JSP 2.0 container (such as Tomcat 5.x), > you can enable support for EL expressions globally in your pages (even > in template text -- it doesn't have to be in a custom tag attribute). > This requires telling the container that you are a Servlet 2.4 webapp, > by including the following as the root element: > > http://java.sun.com/xml/ns/j2ee"; > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; > xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee > http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"; > version="2.4"> > > instead of the DOCTYPE declaration used on previous versions. Doing > this makes the struts-el library totally superfluous -- EL expressions > work as expected on all the standard Struts tags. > > This capability lets you do some cute things, even without a lot of > custom tags. Consider the following example (using JSTL tags) where > "customers" is an attribute that contains an array (or List) of > Customer beans. > > > > Id > Name > > > > ${customer.id} > ${customer.name} > > > > > (Note that you can get the same sort of filtering that > does for you, to avoid cross site scripting attacks, by using things > like "" instead of "${customer.id}" if > you need it.) > > (If you want to do *input* into a table like this, consider using > JavaServer Faces (JSF) components like instead ... it > manages all the hard parts for you.) > > > > > Erik > > > > Craig > > - > 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]
Re: Handle images path in one place
Craig McClanahan wrote: (Note that you can get the same sort of filtering that does for you, to avoid cross site scripting attacks, by using things like "" instead of "${customer.id}" if you need it.) hmm, wonder why I have always thought ${customer.id} would have escaping turned on? Maybe because defaults to doing it by default? But reading the specs it does say the same thing you say above eg you need to use to get that escaping. I think I would prefer to have escaping on for almost all of my ${} expressions with only some exceptions having them turned off. In those cases I think it would be fine to use the tag. I might have to go back and make sure my apps use now instead of the easier to use ${} expression. Unless there is some way to force escaping on for ${} expressions by default? Doesn't look like it to me :( -- Jason Lea -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 265.8.7 - Release Date: 2005.02.10 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Handle images path in one place
Thank you. Erik Craig McClanahan wrote: On Thu, 10 Feb 2005 23:09:51 -0500, Erik Weber <[EMAIL PROTECTED]> wrote: Sorry, I was using the html-el tag, not the html tag: I think you should be able to do what you want without the el tags if you are using JSP 2.0, but to be honest, someone else needs to jump in and bail me out here on that. I think it's a configuration problem. (web app 2.3 v 2.4 or something?) You are definitely on the right track. If you are using a Servlet 2.4/JSP 2.0 container (such as Tomcat 5.x), you can enable support for EL expressions globally in your pages (even in template text -- it doesn't have to be in a custom tag attribute). This requires telling the container that you are a Servlet 2.4 webapp, by including the following as the root element: http://java.sun.com/xml/ns/j2ee"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"; version="2.4"> instead of the DOCTYPE declaration used on previous versions. Doing this makes the struts-el library totally superfluous -- EL expressions work as expected on all the standard Struts tags. This capability lets you do some cute things, even without a lot of custom tags. Consider the following example (using JSTL tags) where "customers" is an attribute that contains an array (or List) of Customer beans. Id Name ${customer.id} ${customer.name} (Note that you can get the same sort of filtering that does for you, to avoid cross site scripting attacks, by using things like "" instead of "${customer.id}" if you need it.) (If you want to do *input* into a table like this, consider using JavaServer Faces (JSF) components like instead ... it manages all the hard parts for you.) Erik Craig - 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]
Re: Handle images path in one place
On Thu, 10 Feb 2005 23:09:51 -0500, Erik Weber <[EMAIL PROTECTED]> wrote: > Sorry, I was using the html-el tag, not the html tag: > > > > I think you should be able to do what you want without the el tags if > you are using JSP 2.0, but to be honest, someone else needs to jump in > and bail me out here on that. I think it's a configuration problem. (web > app 2.3 v 2.4 or something?) You are definitely on the right track. If you are using a Servlet 2.4/JSP 2.0 container (such as Tomcat 5.x), you can enable support for EL expressions globally in your pages (even in template text -- it doesn't have to be in a custom tag attribute). This requires telling the container that you are a Servlet 2.4 webapp, by including the following as the root element: http://java.sun.com/xml/ns/j2ee"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"; version="2.4"> instead of the DOCTYPE declaration used on previous versions. Doing this makes the struts-el library totally superfluous -- EL expressions work as expected on all the standard Struts tags. This capability lets you do some cute things, even without a lot of custom tags. Consider the following example (using JSTL tags) where "customers" is an attribute that contains an array (or List) of Customer beans. Id Name ${customer.id} ${customer.name} (Note that you can get the same sort of filtering that does for you, to avoid cross site scripting attacks, by using things like "" instead of "${customer.id}" if you need it.) (If you want to do *input* into a table like this, consider using JavaServer Faces (JSF) components like instead ... it manages all the hard parts for you.) > > Erik > Craig - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Handle images path in one place
Two things that I think can cause a problem are using a Servlet 2.3 web.xml instead of a Servet 2.4 web.xml and using the "isELIgnored" attribute to the page directive incorrectly. Erik Erik Weber wrote: Sorry, I was using the html-el tag, not the html tag: I think you should be able to do what you want without the el tags if you are using JSP 2.0, but to be honest, someone else needs to jump in and bail me out here on that. I think it's a configuration problem. (web app 2.3 v 2.4 or something?) Erik Neil Aggarwal wrote: Erik: This did not seem to work for me. The varuable is not being substituted. I am using TOmcat 5.0.25 so it should implement JSP 2.0. Here is what I have in my JSP: <% String buttonImageUrl = PathUtil.getImagePath(request,"layout/homeButtonOver.gif"); pageContext.setAttribute("buttonImageUrl",buttonImageUrl); String overImageUrl = PathUtil.getImagePath(request,"layout/homeButtonOver.gif"); pageContext.setAttribute("overImageUrl",overImageUrl); %> onmouseout="setImage('homeButton','${buttonImageUrl}')" > width="140" height="52" /> When I look at the source of the generate page, I get this: It is taking the variables as literals. Any ideas? Thanks, Neil -- Neil Aggarwal, JAMM Consulting, (972)612-6056, www.JAMMConsulting.com FREE! Valuable info on how your business can reduce operating costs by 17% or more in 6 months or less! http://newsletter.JAMMConsulting.com -Original Message- From: Erik Weber [mailto:[EMAIL PROTECTED] Sent: Thursday, February 10, 2005 9:02 AM To: Struts Users Mailing List Subject: Re: Handle images path in one place Using the expression language, you can build paths like this: 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 contains the same images. I would like to have the path to these images into one place an if possible into the same place for all images. For instance in a file and have a tag to access like this like this I can move my images from one folder to another, I will have only one file to update 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] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Handle images path in one place
Sorry, I was using the html-el tag, not the html tag: I think you should be able to do what you want without the el tags if you are using JSP 2.0, but to be honest, someone else needs to jump in and bail me out here on that. I think it's a configuration problem. (web app 2.3 v 2.4 or something?) Erik Neil Aggarwal wrote: Erik: This did not seem to work for me. The varuable is not being substituted. I am using TOmcat 5.0.25 so it should implement JSP 2.0. Here is what I have in my JSP: <% String buttonImageUrl = PathUtil.getImagePath(request,"layout/homeButtonOver.gif"); pageContext.setAttribute("buttonImageUrl",buttonImageUrl); String overImageUrl = PathUtil.getImagePath(request,"layout/homeButtonOver.gif"); pageContext.setAttribute("overImageUrl",overImageUrl); %> onmouseout="setImage('homeButton','${buttonImageUrl}')" > width="140" height="52" /> When I look at the source of the generate page, I get this: It is taking the variables as literals. Any ideas? Thanks, Neil -- Neil Aggarwal, JAMM Consulting, (972)612-6056, www.JAMMConsulting.com FREE! Valuable info on how your business can reduce operating costs by 17% or more in 6 months or less! http://newsletter.JAMMConsulting.com -Original Message- From: Erik Weber [mailto:[EMAIL PROTECTED] Sent: Thursday, February 10, 2005 9:02 AM To: Struts Users Mailing List Subject: Re: Handle images path in one place Using the expression language, you can build paths like this: 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 contains the same images. I would like to have the path to these images into one place an if possible into the same place for all images. For instance in a file and have a tag to access like this like this I can move my images from one folder to another, I will have only one file to update 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]
RE: Handle images path in one place
Erik: This did not seem to work for me. The varuable is not being substituted. I am using TOmcat 5.0.25 so it should implement JSP 2.0. Here is what I have in my JSP: <% String buttonImageUrl = PathUtil.getImagePath(request,"layout/homeButtonOver.gif"); pageContext.setAttribute("buttonImageUrl",buttonImageUrl); String overImageUrl = PathUtil.getImagePath(request,"layout/homeButtonOver.gif"); pageContext.setAttribute("overImageUrl",overImageUrl); %> When I look at the source of the generate page, I get this: It is taking the variables as literals. Any ideas? Thanks, Neil -- Neil Aggarwal, JAMM Consulting, (972)612-6056, www.JAMMConsulting.com FREE! Valuable info on how your business can reduce operating costs by 17% or more in 6 months or less! http://newsletter.JAMMConsulting.com > -Original Message- > From: Erik Weber [mailto:[EMAIL PROTECTED] > Sent: Thursday, February 10, 2005 9:02 AM > To: Struts Users Mailing List > Subject: Re: Handle images path in one place > > > Using the expression language, you can build paths like this: > > > > 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 contains the same images. > >I would like to have the path to these images into one place > an if possible into the same place for all images. > >For instance in a file and have a tag to access like this > > > > > >like this I can move my images from one folder to another, I > will have only one file to update > > > >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]
Re: Handle images path in one place
On Thu, 10 Feb 2005 15:18:27 +0100, Gaet <[EMAIL PROTECTED]> wrote: > Hello, > > I'm writting a web application using J2EE where several pages can contains > the same images. > I would like to have the path to these images into one place an if possible > into the same place for all images. > For instance in a file and have a tag to access like this > > > like this I can move my images from one folder to another, I will have only > one file to update > > Does somebody use something similar? Yes. I do this. My HTML is a little different, e.g. resource.do?alias='dog'> or but the idea is the same. The difference in the tag should tell you how it is done. Jack -- "You can lead a horse to water but you cannot make it float on its back." "Heaven has changed. The Sky now goes all the way to our feet. ~Dakota Jack~ "This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation." - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Handle images path in one place
One alternative is to use the "srcKey" attribute for both the and tags to specify a key in your Message Resources properties file whose value is the URL. -Bill Siggelkow Gaet wrote: Hello, I'm writting a web application using J2EE where several pages can contains the same images. I would like to have the path to these images into one place an if possible into the same place for all images. For instance in a file and have a tag to access like this like this I can move my images from one folder to another, I will have only one file to update Does somebody use something similar? TIA Gaet - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Handle images path in one place
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" Sent: Thursday, February 10, 2005 4:02 PM Subject: Re: Handle images path in one place Using the expression language, you can build paths like this: 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 contains the same images. I would like to have the path to these images into one place an if possible into the same place for all images. For instance in a file and have a tag to access like this like this I can move my images from one folder to another, I will have only one file to update 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]
Re: Handle images path in one place
From: "Gaet" <[EMAIL PROTECTED]> > I'm writting a web application using J2EE where > several pages can contains the same images. > I would like to have the path to these images into > one place an if possible into the same place for all images. I have Apache serve images directly, so all my webapps have and those files live under Apache's document root. (For development which I do with Tomcat alone, they're under the ROOT webapp.) -- Wendy Smoak - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Handle images path in one place
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" Sent: Thursday, February 10, 2005 4:02 PM Subject: Re: Handle images path in one place > Using the expression language, you can build paths like this: > > > > 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 contains the same images. > >I would like to have the path to these images into one place an if possible into the same place for all images. > >For instance in a file and have a tag to access like this > > > > > >like this I can move my images from one folder to another, I will have only one file to update > > > >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]
Re: Handle images path in one place
Using the expression language, you can build paths like this: 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 contains the same images. I would like to have the path to these images into one place an if possible into the same place for all images. For instance in a file and have a tag to access like this like this I can move my images from one folder to another, I will have only one file to update Does somebody use something similar? TIA Gaet - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]