File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
dennis deng
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Adam Hardy
Ranch Hand
Posts: 567
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Erik Hatcher
Author
Ranch Hand
Posts: 111
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Adam Hardy
Ranch Hand
Posts: 567
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic