简体   繁体   中英

struts2 form submit not hitting method

I have a .jsp form like so

<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

    <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

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

but when I click the button, auditLogReport method does not get hit. What I see in the browser url is 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. That prevented the .action from being appended but the button still didn't work. Plus it caused the .css and images from being found. I have a link that uses the default execute() method and that works ok.

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.

Suggestions?

The problem turned out to be a Date parameter. Apparently struts2 doesn't like them.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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