0

I have a Struts Action that has a DTO as a member:

public class MyAction {
   private MyDTO dto;

   void execute() {
      String bar = dto.getBar() ;  
     //struts has mapped GET parameter dto.bar by calling dto.setBar()
     // do something with bar:
     return bar != null ? SUCCESS : INPUT;
    }
}

I want the parameter named "b" to be mapped to dto.bar, simply to make my GET url cleaner. Instead of: http://myurl?dto.bar=xxx I want: http://myurl?b=xxx

I know I can do this by adding to my Action a setB(final String b), but that would make my code more brittle and harder to understand.

Is there a way I can tell Struts to do this mapping, so that for a url of http://myurl?b=xxx, MyAction.getDto.setBar() is called?

4

1 に答える 1

1

これを実現するために、エイリアシング インターセプトを使用できる場合があります。チェックアウト:

http://www.opensymphony.com/webwork/wikidocs/Alias%20Interceptor.html

于 2011-01-05T00:06:36.370 に答える