我在JSP的形式。 有两个提交按钮:“搜索”和“新增”按钮。 我已成立自己的方法属性的每个按钮。
<s:form name="searchForm" action="employeeAction" method="post">
<s:textfield name="id" label="Employee ID"/>
<s:textfield name="name" label="Employee Name"/>
<s:submit value="Search" method="doSearch"/>
<s:submit value="Add New" method="doAddNew"/>
</s:form>
在struts.xml中
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="index" />
<global-results>
<result name="error">/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error"/>
</global-exception-mappings>
</package>
<package name="example" namespace="/example" extends="default">
<action name="employeeAction" class="example.EmployeeAction">
<result name="search">/example/search.jsp</result>
<result name="add">/example/add.jsp</result>
</action>
</package>
</struts>
在EmployeeAction类
public class EmployeeAction extends ActionSupport {
private static final Logger logger = Logger.getLogger(EmployeeAction.class);
@Override
public String execute() throws Exception {
logger.info("Calling execute!");
return SUCCESS;
}
public String doSearch() throws Exception {
logger.info("Calling doSearch!");
return "search";
}
public String doAddNew() throws Exception {
logger.info("Calling doAddNew!");
return "add";
}
}
问题是,当我点击“搜索”或“新添加”按钮,该方法doSearch()或doAddNew()从未被调用,而不是叫方法execute()。 什么是错我上面的代码?
我用struts V2.3。