2016-06-09 76 views
0

我有一個.JSP形式,像這樣Struts2的表單提交不打方法

<s:form action="AuditLogReport">Source IP<br> 
<input type="text" class="auditLogSearch" name="sourceIp" value="All"> 
<input type="submit" value="Submit"/> 
</s:form> 

而我在struts.xml定義

<action name="AuditLogReport" 
    class="com.mycom.selfservice.actions.AuditLogAction" method="auditLogReport"> 
       <result name="success">jsp/AuditLog.jsp</result> 
       <result name="error">jsp/Error.jsp</result> 
    </action> 

這裏是我的類定義

public class AuditLogAction extends ActionSupport implements Action,ServletRequestAware { 

在我的AuditLogAction類中有一個方法

public String auditLogReport() { 
    System.out.println("Im in auditLogReport..."); 

但是當我點擊按鈕時,auditLogReport方法不會被擊中。我在瀏覽器url中看到的是http://localhost:7001/BPSelfServicePortal/AuditLogReport.action

這是追加.action,我認爲它是爲什麼它找不到方法。所以我試圖在struts.xml中把

<constant name="struts.action.extension" value=""/> 

。這阻止了.action被添加,但按鈕仍然無效。另外它會導致找到.css和圖像。我有一個使用默認execute()方法的鏈接,並且工作正常。

如果我只是刪除url中的.action,然後回車,它會觸發該方法,但是表單中的值都不會被傳遞。

對此提出建議?

回答

0

問題原來是一個Date參數。顯然struts2不喜歡它們。

public Date getFromDate() { 
    return fromDate; 
} 
public void setFromDate(Date fromDate) { 
    this.fromDate = fromDate; 
} 

改成了

public String getFromDate() { 
    return fromDate; 
} 
public void setFromDate(String fromDate) { 
    this.fromDate = fromDate; 
} 

然後它的工作!