rt
为什么会这样子怪,一开始是好正常的,但我改程序时加入了namespace属性后发现不会用这个属性,总是提示这个错误的,那么我就改回原来程序的样子(没有namespace),但为什么怎样运行都出现这个错误 ??重启tomcat多次亦是如此
HTTP Status 404 - There is no Action mapped for namespace / and action name LoginRegist.
--------------------------------------------------------------------------------
type Status report
message There is no Action mapped for namespace / and action name LoginRegist.
description The requested resource (There is no Action mapped for namespace / and action name LoginRegist.) is not available.
login.jsp:
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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><s:text name="LoginPage"/></title>
</head>
<body>
<s:form action="LoginRegist" method="post" theme="simple">
<s:text name="UserName"/><s:textfield name="userName"/><br />
<s:text name="UserPass"/> <s:password name="userPassword"/><br />
<s:submit/><s:reset/>
</s:form>
</body>
</html>
welcome.jsp:
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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><s:text name="WelcomePage"/></title>
</head>
<body>
欢迎再次光临,${sessionScope.userName }!<br />
您的当时访问时间为:<%=new java.util.Date().toLocaleString() %>
<br /><br />
<a href="GetBooks.action">查看所有书籍</a>
</body>
</html>
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="LR" extends="struts-default">
<action name="/LoginRegist" class="com.struts2.LoginRegistAction">
<result name="input">/Login.jsp</result>
<result>/WEB-INF/welcome.jsp</result>
<result name="error">/Login.jsp</result>
</action>
</package>
<package name="GB" extends="struts-default">
<action name="GetBooks" class="com.struts2.GetBooksAction">
<result>/WEB-INF/booksList.jsp</result>
<result name="login">/login.jsp</result>
</action>
</package>
</struts>
LoginRegistAction.java:
package com.struts2;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class LoginRegistAction extends ActionSupport implements ModelDriven<LoginUser> {
/**
*
*/
private static final long serialVersionUID = 1L;
LoginUser loginUs = new LoginUser();
@Override
public LoginUser getModel() {
if(loginUs == null)
loginUs = new LoginUser();
return loginUs;
}
public void validation() {
if(loginUs.getUserName() == null || loginUs.getUserName().equals(""))
addFieldError("userName", getText("user.required"));
if(loginUs.getUserPassword() == null || loginUs.getUserPassword().equals(""))
addFieldError("userPassword", getText("pass.required"));
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
if(loginUs.getUserName().equals("QQAA2233") && loginUs.getUserPassword().equals("3322QQAA")) {
ActionContext.getContext().getSession().put("userName", loginUs.getUserName());
return SUCCESS;
}
else
return ERROR;
}
}
LoginUser.java:
package com.struts2;
public class LoginUser {
private String userName;
private String userPassword;
public void setUserName(String userName) { this.userName = userName; }
public String getUserName() { return this.userName; }
public void setUserPassword(String userPassword) { this.userPassword = userPassword; }
public String getUserPassword() { return this.userPassword; }
}
我试过添加namespace="/"这语句都不行,加上我最初的程序是一个namespace属性都没有的,都可以成功运行,,但自从namespace后就不行了。。
7 个解决方案
“/” 这个命名空间下 找不到 “LoginRegist”这个action
“/” 这个命名空间下 找不到 “LoginRegist”这个action
namespace 表示包命名,作用就是方便 struts.xml 中代码清晰,方便管理
你要是 namespace="/" 那就需要
<result name="input">Login.jsp</result>
这样写,如果 namespace="/test" 的话,就可以像之前那样