2012-05-03 66 views
1

使用如何治療URL字符串作爲參數,而不具有「?」操作名稱後的字符?Struts 2的動態URL中搜索

比方說,例如我們從數據庫用戶名:JR,千斤頂,J,等...

我想是使用domain.com/user/jr查看他們的個人資料,domain.com/user /插孔,domain.com/user/j等

是否有這些辦法嗎?

從例如,JR,千斤頂,j是動態的,在觀看他們的簡檔中使用的密鑰。

回答

1

使用Wildcard mappings

動作註解一個例子(公約插件):

struts.xml

<constant name="struts.enable.SlashesInActionNames" value="true" /> 
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false" /> 
<constant name="struts.patternMatcher" value="regex" /> 

@Action(value = "user/{userName}", results = { 
     @Result(location = "user.jsp") 
}) 
public class UserAction extends ActionSupport implements Preparable { 

    private String userName; // with getter & setter 

    public void prepare() { 
     // getUserByUserName(userName) 
    } 
} 

0

我想你正在尋找的是Struts 2 REST插件,因爲你正在尋找REST風格的URL。

http://struts.apache.org/2.x/docs/rest-plugin.html

我不記得是否有插件替換正常的「動作」類映射,但我認爲它可能。也就是說,我認爲有其存在後,所有的行動都在我鏈接的信息指定要按照慣例映射。

祝你好運。