This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes How to pass a dynamic parameter in struts-config.xml? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to pass a dynamic parameter in struts-config.xml?" Watch "How to pass a dynamic parameter in struts-config.xml?" New topic
Author

How to pass a dynamic parameter in struts-config.xml?

dennis deng
Ranch Hand

Joined: Nov 07, 2001
Posts: 42
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)
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 565
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.
Erik Hatcher
Author
Ranch Hand

Joined: Jun 11, 2002
Posts: 111
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.


Co-author of Lucene in Action
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 565
Hi Erik,
you've been thinking laterally. Sounds good. Are there any pitfalls? Does it work for off-site URLs? Can you show a code snippet?
Ted Husted
Author
Ranch Hand

Joined: Dec 02, 2002
Posts: 37
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>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to pass a dynamic parameter in struts-config.xml?
 
Similar Threads
URL rewriting and Struts how-to
How to pass a dynamic parameter in struts-config.xml?
Spring security: pass additional parameter when performing login
Multiple Struts-config.xml in Jboss 4.2.1
ApplicationResource. properties file ?