2012-12-24 32 views

回答

0

你確定這真的是你需要做什麼? Struts2爲您提供所有即用即用的工具,以實現幾乎所有的結果。

但如果你真的想要實現您的自定義操作映射,然後在第9章看一看,從266到269頁,Struts2 Web 2.0 Projects by Ian Roughley;

ActionMapper接口提供了兩種方法:一種將URL轉換爲動作映射,另一種將另一種方式從動作映射轉換爲URL。

所以,你在你的Action映射從struts.xml中像往常一樣映射你的行動和你的結果類型,而不是。

看看在DefaultActionMapper source code太...沒有結果類型的任何地方,這不是他們的管理。

public ActionMapping getMapping(HttpServletRequest request, 
           ConfigurationManager configManager) { 
    ActionMapping mapping = new ActionMapping(); 
    String uri = getUri(request); 

    int indexOfSemicolon = uri.indexOf(";"); 
    uri = (indexOfSemicolon > -1) ? uri.substring(0, indexOfSemicolon) : uri; 

    uri = dropExtension(uri, mapping); 
    if (uri == null) { 
     return null; 
    } 

    parseNameAndNamespace(uri, mapping, configManager); 

    handleSpecialParameters(request, mapping); 

    if (mapping.getName() == null) { 
     return null; 
    } 

    parseActionName(mapping); 

    return mapping; 
} 
+0

感謝fow the answear,當需求有錯誤的子域名時,我需要返回一些頁面。然後必須通過Interceptor –

+0

來完成。當然,你可以使用攔截器來完成。在SO搜索,它的全部如何做到這一點 –

+0

這個我知道答案,我只是不希望創建攔截檢查的子域名的正確性。動作映射器已用於自己的目的,所以我想在Action映射 –

0

的ActionMapping getMapping(javax.servlet.http.HttpServletRequest的請求, ConfigurationManager中CONFIGMANAGER)

Expose the ActionMapping for the current request 

Parameters: 
    request - The servlet request 
    configManager - The current configuration manager 
Returns: 
    The appropriate action mapping String or null if mapping cannot be determined 
+0

即自定義全局結果無法返回,因爲全局結果不是一個操作。我理解正確嗎? –

相關問題