0

我對將代碼隱藏註釋轉換爲常規struts.xml文件感到困惑。Struts 2插件轉換 - 從Codebehind到Convention插件

如何識別動作類中的動作名稱?因爲如果寫入方法public String list{} - 動作與JSP的匹配product-list.jsp將自動識別頁面,並且URL是product!list。什麼是傳統插件?

當前網址:

http://localhost:7001/example/product!search - JSP名稱product-search.jspProductAction - 動作類。

請告訴我如何配置struts.xml文件,它等於上面的配置。

我試圖象下面這樣:

<package name="example" namespace="/" extends="struts-default"> 
    <action name="Search"> 
    <result>product-search.jsp</result> 
    </action>   
</package> 

錯誤:

org.apache.struts2.dispatcher.Dispatcher - Could not find action or result 
There is no Action mapped for namespace/and action name part. - [unknown location] 
+0

請讓我知道如果你不明白這個問題.. – user2444474

回答

0

在Struts2的動作映射方法。上面的網址,你應該映射爲

<package name="example" namespace="/" extends="struts-default"> 
    <action name="product" method="search"> <!-- case sensitive --> 
    <result>product-search.jsp</result> 
    </action> 
</package> 

或通過註釋

@Namespace("/") 
public class ProductAction extends ActionSupport { 

    public String execute() { 
    return SUCCESS; 

    } 

    @Action(value="product", 
    [email protected](location="/product-list.jsp") 
) 
    public String search() { 
    return SUCCESS; 
    } 
} 

注意,該方法execute沒有映射,所以它不會執行。如果你需要該方法執行,你應該創建映射。爲此,您可以在課堂或方法execute上放置註釋。

更多可以在site上找到的例子。