Struts アクションを注釈に変換する前は、プロジェクトは正常に機能していました。しかし、今私は注釈をやろうとしていて、このエラーが発生しました。アクションを含む以前のstruts.xml
ファイルは次のとおりです。
<action name="searchUser"
class="net.viralpatel.struts2.action.MemberCrudOperations"
method="getUserById">
<result name="success">EditMember.jsp</result>
</action>
今、私はそれを注釈に変換しています、そして私のMemberCrudOperations
クラス
package net.viralpatel.struts2.action;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import com.opensymphony.xwork2.ActionSupport;
@Namespace("/")
@Result(name="success", location="EditMember.jsp")
public class MemberCrudOperations extends ActionSupport{
private static final long serialVersionUID = 1L;
Employee employee;
List<Employee> emps = new ArrayList<Employee>();
public String fName;
public String lName;
public Long employeeId;
private Connection connection;
public MemberCrudOperations() {
connection = DbUtil.getConnection();
}
@Action(value="searchUser")
public String getUserById() {
employee=new Employee();
try {
PreparedStatement preparedStatement = connection.
prepareStatement("select * from employee where first LIKE ? OR last LIKE ? ");
preparedStatement.setString(1, "%"+fName+"%");
preparedStatement.setString(2, "%"+lName+"%");
ResultSet rs = preparedStatement.executeQuery();
if (rs.next()) {
employee.setId(rs.getInt("id"));
employee.setAge(rs.getInt("age"));
employee.setFirstName(rs.getString("first"));
employee.setLastName(rs.getString("last"));
}
} catch (SQLException e) {
e.printStackTrace();
}
return "success";
}
そして、私のビューファイルは次のとおりです。
<s:form method="post" theme="simple" action="searchUser">
<table border="1">
<tr>
<td>First Name: </td>
<td><s:textfield name="fName"></s:textfield></td>
</tr>
<tr>
<td>Last Name: </td>
<td><s:textfield name="lName"></s:textfield></td>
</tr>
<tr>
<td></td>
<td align="right"><s:submit name="search" value="Search" ></s:submit></td>
</tr>
</table>
</s:form>
Struts 問題レポート
Struts has detected an unhandled exception:
Messages:
There is no Action mapped for namespace [/] and action name [searchUser] associated with context path [/Struts2_Hello_World].
Stacktraces
There is no Action mapped for namespace [/] and action name [searchUser] associated with context path [/Struts2_Hello_World]. - [unknown location]
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:552)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)