我收到此错误:
HTTP Status 404 - There is no Action mapped for namespace [/] and action name [loginForm] associated with context path
web.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
struts.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration
2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="loginForm" class="org.nitish.action.LoginAction">
<result name="success">Welcome.jsp</result>
<result name="failure">index.jsp</result>
</action>
</package>
<bean name="loginForm" class="org.nitish.form.LoginForm"></bean>
<constant name="struts.devMode" value="true" />
<constant name="struts.mapper.alwaysSelectFullNamespace" value="true" />
</struts>
index.jsp
:
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login page | Hello World Struts application in Eclipse</title>
</head>
<body>
<h1>Login</h1>
<s:form action="loginForm">
<s:textfield name="userName" label="Username" />
<s:password name="password" label="Password" />
<s:submit />
</s:form>
</body>
</html>
文件夹结构为:
编辑:
动作代码:
public class LoginAction extends ActionSupport {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String target = null;
LoginForm loginForm = (LoginForm)form;
if(loginForm.getUserName().equals("admin")
&& loginForm.getPassword().equals("admin123")) {
target = "success";
request.setAttribute("message", loginForm.getPassword());
}
else {
target = "failure";
}
return mapping.findForward(target);
}
}