简体   繁体   English

struts2表单提交未命中方法

[英]struts2 form submit not hitting method

I have a .jsp form like so 我有一个.jsp形式像这样

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

And my struts.xml is defined 我的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>

Here is my class definition 这是我的班级定义

public class AuditLogAction extends ActionSupport implements Action,ServletRequestAware {

And in my AuditLogAction class there is a method 在我的AuditLogAction类中,有一个方法

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

but when I click the button, auditLogReport method does not get hit. 但是当我单击该按钮时,auditLogReport方法不会被点击。 What I see in the browser url is http://localhost:7001/BPSelfServicePortal/AuditLogReport.action 我在浏览器网址中看到的是http://localhost:7001/BPSelfServicePortal/AuditLogReport.action

It is appending .action which I think is why it doesn't find the method. 我认为这就是为什么找不到方法的原因。 So I tried putting 所以我试着把

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

in the struts.xml. 在struts.xml中。 That prevented the .action from being appended but the button still didn't work. 这阻止了.action的附加,但是按钮仍然不起作用。 Plus it caused the .css and images from being found. 加上它导致发现.css和图像。 I have a link that uses the default execute() method and that works ok. 我有一个使用默认execute()方法的链接,该链接正常运行。

If I simply remove the .action in the url and hit enter, it hits the method but then none of the values in the form get passed. 如果我只是删除url中的.action并按Enter,它将命中该方法,但是没有任何形式的值被传递。

Suggestions? 有什么建议吗?

The problem turned out to be a Date parameter. 问题原来是日期参数。 Apparently struts2 doesn't like them. 显然struts2不喜欢它们。

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

Changed it to 更改为

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

And then it worked! 然后它起作用了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM