struts2 初学求解问题
问题:
HTTP Status 404 - There is no Action mapped for action name loginuser.
--------------------------------------------
type Status report
message There is no Action mapped for action name loginuser.
description The requested resource (There is no Action mapped for action name loginuser.) is not available.
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>
</web-app>
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="false" />
<include file="trylogin.xml"/>
</struts>
trylogin.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="login" namespace="/jsp" extends="default">
<action name="loginuser" class="loginaction.loginaction" method="judge">
<result name="success">/jsp/success.jsp</result>
<result name="fail">/jsp/fail.jsp</result>
</action>
</package>
</struts>
login.jsp:
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>
login.jsp
</title>
</head>
<body>
<s:form action="loginuser.action">
<s:textfield key="username"/>
<s:password key="password"/>
<s:submit/>
</s:form>
</body>
</html>
loginaction.java
package loginaction;
public class loginaction
{
private String username;
private String password;
public void setUsername(String username)
{
this.username=username;
}
public String getUsername()
{
return username;
}
public void setPassword(String password)
{
this.password=password;
}
public String getPassword()
{
return password;
}
public String judge()
{
if(username.equals("luozixuan")&&password.equals("123456"))
{
return "success";
}
else
{
return "fail";
}
}
}
success.jsp 和fail.jsp都是与login.jsp放在一起的,只有简单的输出功能
贴图不会贴,文件安放
根目录:mystruts
第一层:jsp:放着login.jsp,success.jsp,fail.jsp
WEB-INF:第二层classes:structs.xml,trylogin.xml,文件夹loginaction:第三层:loginaction.class
lib:各种.jar文件
src:structs.xml,trylogin.xml,文件夹loginaction:第三层:loginaction.java
web.xml
[解决办法]
文件安放和struts自带的app下的struts2-blank一样。急急急!!!!!