struts2.5 测试action老是404,大神救救我。。
故宫遥望 2019-01-24 09:06:38 http://127.0.0.1:8080/juicy/LoginAction.action?username=x&pwd=y
404报错
ype Status Report
Message /juicy/LoginAction.action
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
-------------------------------------------------------------
login.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="LoginAction.action" >
用户名:<input type="text" name="username"><br>
密码<input type="text" name="pwd"><br>
<input type="submit" value="提交">
</form>
</body>
</html>
-------------------------------------------------------------
web.xml 和struts.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">
<display-name>Struts Application</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
</web-app>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<!-- START SNIPPET: xworkSample -->
<struts>
<!-- Struts。xml的配置文件 -->
<!-- 所有匹配*.action的请求都由struts2处理 -->
<constant name="struts.action.extension" value="action" />
<!-- 是否启用开发模式 -->
<constant name="struts.devMode" value="true" />
<!-- struts配置文件改动后,是否重新加载 -->
<constant name="struts.configuration.xml.reload" value="true" />
<!-- 请求参数的编码方式 -->
<constant name="struts.i18n.encoding" value="utf-8" />
<!-- 每次HTTP请求系统都重新加载资源文件 -->
<constant name="struts.i18n.reload" value="true" />
<!-- 让struts2支持动态方法调用 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<!--新建一个package,name随意,extends自struts-default -->
<package extends="struts-default" name="default" strict-method-invocation="false" >
<action name="LoginAction" method="Login" class="struts.LoginAction">
<result name="success">success.jsp</result>
<result name="error">error.jsp</result>
</action>
</package>
</struts>
<!-- END SNIPPET: xworkSample -->
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
action代码:
package struts;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport{
//继承ActionSupport类以直接使用SUCCESS, LOGIN等变量和重写execute等方法
//声明用户名和密码的实例变量;
public String username;
public int pwd;
//需要在xml里调用的Login方法(返回值为String):
public String Login(){
System.out.println(username+" "+pwd);
if(username.trim().equals("aaa")&&pwd==123){
return "success";
}else{
return "error";
}
}
//系统生成的get和set方法
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getPwd() {
return pwd;
}
public void setPwd(int pwd) {
this.pwd = pwd;
}
}
tomcat 8.5 struts.xml和web.xml目录如截图