Hi, guys. I wonder How to pass a dynamic parameter in struts-config.xml? such as <forward name="home" path="http://localhost:8080/colorimage/home.do" redirect="true"/> i want put one parameter hostIP in the itatics word and deploy the real hostIP in somewhere?so how can i do it ? Thanks alot. Dennis
Sun Certificated JAVA Programmer(SCJP)<br />Sun Certificated JAVA Developer(SCJD)<br />Sun Certified Web Component Developer(SCWCD)
Hi Dennis, presumably this hostIP that you want to make dynamic is not in your website. Presumably you also do not want to list all your possible hostIP parameters as seperate forwards in your action mappings, giving them seperate names and choosing the one you want dynamically as the action.perform() or .execute() return parameter. I think you may be able to do it by calling response.sendRedirect(myURL) in the action and then returning null as the forward. I don't think a straightforward forward() would work since it's a whole new host. Adam
I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Rather than doing mapping.findForward() in your Action, simply create a new ActionForward with the dynamic URL you want and return that from your action. Its pulling some information out of struts-config, but its a good way to forward to dynamic URL's.
As Erik says, a better way to go is to construct an ActionForward within an Action and return that. To keep from hardcoding the path in Java code, you can load a separate configuration servlet or (in Struts 1.1) use a PlugIn Action to load a property file with this type of deployment parameters. The Artimus application bundled with Struts in Action uses a resource servlet to load a properties file. Another approach is to put the path in as the Action parameter property. The Action can then read in the parameter property to construct the ActionForward.
<a href="http://husted.com/struts/book.html" target="_blank" rel="nofollow">Struts in Action</a>