日期:2014-05-17  浏览次数:20961 次

求教关于struts2的问题:
1.No configuration found for the specified action: 'login' in namespace: ''. Form action defaulting to 'action' attribute's literal value.

2.HTTP Status 404 - There is no Action mapped for namespace / and action name login.
  Could not find action or result



<?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为配置文件根元素-->
<struts>
<constant name="struts.custom.i18n.resources" value="messageResource"> </constant>
<!-- Action必须放在指定的包名空间中-->
<package name="struts2" extends="struts-default">
<!-- 定义login的Action,其实现类为com.javaweb.ch15.action.LoginAction2-->
<action name="login" class="com.javaweb.ch15.LoginAction3">
<!-- 定义处理结果与视图资源之间的关系-->
<result name="success">/login_success.jsp</result>
<result name="error">/login_failure.jsp</result>
<result name="input">/login.jsp</result>
</action>
</package>
</struts>




package com.javaweb.ch15;
import com.opensymphony.xwork2.ActionContext;

public class LoginAction {
private String uname;
private String upassword;

//获得uname值
public String getUname() {
return uname;
}

//设置uname值
public void setUname(String uname) {
this.uname = uname;
}

//获得password值
public String getUpassword() {
return upassword;
}

//设置password值
public void setUpassword(String upassword) {
this.upassword = upassword;
}

public String execute() throws Exception {
//new一个LoginCheck对象
LoginCheck lc = new LoginCheck();
//调用业务逻辑组件的判断功能来判断
if(lc.isLogin(getUname(),getUpassword())){
//如果为合法用户,在session范围中添加属性login,其属性值为true,
ActionContext.getContext().getSession().put("login", "true");
return "success";
}else{
return "error";
}
}
}



<%@page contentType="text/html;charset=gb2312"%>
<html>
<head>
<title>用户登录</title>
</head>
<body>
<center>
<h2>用户登录</h2>

<%--登录表单--%>
<form action="login.action" method="post">
<table>
<tr>
<td>用户名:</td>
<%--接收用户输入的用户名,其name属性为uname--%>
<td><input type="text" name="uname"></td>
</tr>
<tr>
<%--接收用户输入的密码,其name属性为upassword--%>
<td>密&nbsp;&nbsp;码:</td>
<td><input type="password" name="upassword"></td>
</tr>
<tr>
<td colspan="2">
<%--登录按钮和重置按钮--%>
<input type="submit" value="登录">
<input type="reset" value="重置">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaL