eclipse struts2 显示action方法那时 404错误

以前都用myeclipse的,现在换成eclipse感觉各种纠结。。
弄了半天了还是这个错误。。求助。。
或者发个eclipse struts2的例子给我也行~~
struts2.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>

<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />

<package name="default" namespace="/" extends="struts-default">

<action name="user" class="service.myAction">
<result name="login_success">/NewFile.jsp</result>
<result name="login_failure">/index.jsp</result>
</action>
</package>

</struts>

ACTION的java代码
package service;

import com.opensymphony.xwork2.ActionSupport;

public class myAction extends ActionSupport{
public String login() throws Exception{
if(name=="111"&&password=="111"){
return "login_success";
}
return "login_failure";
}

private String name;
private String password;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}

}

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">

<display-name>Struts Blank</display-name>

<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>

jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<s:if test="#session.fullname==null">
<form action="user!login.Action">
<input name="name" type="text" />
<input name="password" type="password" />
<input type="submit" />
</form>
</s:if>
<s:else>

</s:else>

</body>
</html>
哎。。弄了又弄了很久,还是这样,算了,大家谁给发我一个eclipse的小例子。。我的邮箱ismycy@qq.com

action方法404错误是因为struts.xml中配置的路径是错误的。
struts.xml配置如下:
struts.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!-- 2013.8.16 -->
<package name="first" extends="struts-default" namespace="/"><!-- 定义一个package -->
<!-- 对action返回结果的配置 -->
<action name="loginA" class="action_struts.LoginAction">
<result name="success" type="dispather">/12.2.2.welcome.jsp</result>
<result name="login">/12.2.2.index.jsp</result>
</action>
</package>
</struts>
在result标签中的路径一定要配置正确,否则是无法找到资源。
温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2016-08-10
你好,这在用什么工具做开发是必然关系的。你自己检查 jar包是否正确导入,
还有你eclipse中本工程的名字是WebApp_9吗?要确保和web.xml中写的一致。
<web-app id="WebApp_9" version="2.4"
另外,你要是能把错误信息发上来就更好了,先看报错,在看代码。

后来我帮你调试了,问题在这里:
<form action="user!login.Action">
修改成:<form action="user!login">或者<form action="user!login.action">追问

我这么改后是这样的哦
虽然还是404不过变了一高级一些。。会不会是好兆头。。。那个包我把struts2-blank里面的都复制到lib里面了。。

追答

算了,给你发一个吧。我按照你的代码敲的,怎么可能有错呢。你修改完配置文件记得重启服务器。要不然就会报错。

本回答被提问者采纳
第2个回答  2012-03-11
<action name="user" class="service.myAction">
<result name="login_success">/NewFile.jsp</result>
<result name="login_failure">/index.jsp</result>
</action>
这写错了,没写method,method缺省值是excute,看你的写法,应该是要调用login,所以在action标签里面加个参数method="login"追问

There is no Action mapped for namespace [/] and action name

警告: No configuration found for the specified action: 'user!login' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
警告: No configuration found for the specified action: 'user!login' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
警告: Could not find action or result

相似回答