struts2 表单提交未命中方法

struts2 form submit not hitting method

我有一个像这样的 .jsp 表格

<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>

这是我的class定义

public class AuditLogAction extends ActionSupport implements Action,ServletRequestAware {

并且在我的 AuditLogAction class 中有一个方法

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

但是当我点击按钮时,auditLogReport 方法没有被点击。我在浏览器中看到的 url 是 http://localhost:7001/BPSelfServicePortal/AuditLogReport.action

它附加了 .action,我认为这就是它找不到方法的原因。所以我试着把

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

在struts.xml。这阻止了 .action 被附加,但按钮仍然不起作用。加上它导致 .css 和图像被发现。我有一个 link 使用默认的 execute() 方法并且工作正常。

如果我简单地删除 url 中的 .action 并按下回车键,它会触发该方法,但随后表单中的 none 值会被传递。

建议?

原来是日期参数的问题。显然 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;
}

然后成功了!