大家帮帮忙吧:警告: No configuration found for the specified action: 'login'

桐柏小仙 2010-10-16 10:11:13
请教各位大师,这个问题怎么解决,index按钮提交后都是找不到资源(The requested resource (/struts2_01/login) is not available.
),控制台信息容下:
警告: No configuration found for the specified action: 'login' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
2010-10-16 9:46:49 org.apache.struts2.components.Form evaluateExtraParamsServletRequest
警告: No configuration found for the specified action: 'login' in namespace: ''. Form action defaulting to 'action' attribute's literal value.


  
struts.xml:

<include file="struts-default.xml"></include>
<constant name="struts.devMode" value="true" />
<constant name="struts.i18n.encoding" value="GB2312" />
<package name="struts2" namespace="/" extends="struts-default">
<action name="login" class="com.test.action.LoginAction">
<result name="success">welcome.jsp</result>
<result name="fail">regist.jsp</result>
<result name="input">index.jsp</result>

</action>

<!-- 定义多动作控制器方法一 -->
<action name="loginAction" class="com.zpj.action.LoginAction">
<result name="ok">/success.jsp</result>
<result name="saveUserOk">/success.jsp</result>
<result name="checkUserOk">/success.jsp</result>
<result name="input" type="redirect">/index.jsp</result>
</action>

<!-- 定义多动作控制器方法二 -->
<action name="*loginDo" method="{1}" class="com.zpj.action.LoginAction">
<result name="ok">/success.jsp</result>
<result name="saveUserOk">/success.jsp</result>
<result name="checkUserOk">/success.jsp</result>
<result name="input" type="redirect">/index.jsp</result>
</action>

</package>

index.jsp:


<body>
<s:form action="login" method="post">
<s:textfield name="users.username" label="用户名"></s:textfield>
<s:password name="users.password" label="用户名"></s:password>
<s:submit label="测试"></s:submit>
</s:form>

<center>

<s:form action="loginAction!saveUser">
<s:textfield name="loginBean.username" label="姓名"></s:textfield>
<s:password name="loginBean.pwd" label="密码"></s:password>
<s:submit label="登陆"></s:submit>
</s:form>
<hr>

<s:form action="checkUserloginDo">
<s:textfield name="loginBean.username" label="姓名"></s:textfield>
<s:password name="loginBean.pwd" label="密码"></s:password>
<s:submit label="登陆"></s:submit>
</s:form>
<hr>

<s:form action="loginDo">
<s:textfield name="loginBean.username" label="姓名"></s:textfield>
<s:password name="loginBean.pwd" label="密码"></s:password>
<s:submit label="登陆"></s:submit>
</s:form>
</center>
</body>


LoginAction.class:

package com.zpj.action;

import com.opensymphony.xwork2.ActionSupport;
import com.zpj.domain.LoginBean;

public class LoginAction extends ActionSupport {

/**
*
*/
private static final long serialVersionUID = 1L;
private LoginBean loginBean;

public LoginBean getLoginBean() {
return loginBean;
}

public void setLoginBean(LoginBean loginBean) {
this.loginBean = loginBean;
}

/*
* 默认的validate()方法;
*/
public void validate() {
System.out.println("这个是validate方法=====1");
super.validate();
}

/*
* 执行完这个方法后将执行默认的validate()方法;
*/
public void validateSaveUser() {
System.out.println("这个是validateSaveUser方法=====2");
super.validate();
}

/*
* 默认的execute()方法;
*/
public String execute() throws Exception {
System.out.println("这个是execute方法=====3");
return "ok";
}

/*
* 如果执行了此方法,则不再执行默认的execute()方法;
*/
public String saveUser() throws Exception {
System.out.println("这个是saveUser方法=====4");
return "saveUserOk";
}

/*
* 如果执行了此方法,则不再执行默认的execute()方法;
*/
public String checkUser() throws Exception {
System.out.println("这个是checkUser方法=====5");
return "checkUserOk";
}
}


LoginAction.class

package com.test.action;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {


/**
*
*/
private static final long serialVersionUID = 1L;
private Users users;

public LoginAction(){
//System.out.println("构造函数执行");
}

public Users getUsers() {
return users;
}
public void setUsers(Users users) {
this.users = users;
}
public String execute () throws Exception {
System.out.println("控制其11方法执行"+this.users.getPassword());

if ("root".equals(this.users.getUsername())&&"root".equals(this.users.getPassword())) {
return "success" ;
} else {
this.addFieldError("users.username", "用户名或密码错误") ;
return "input" ;
}
}

public String login () throws Exception {
System.out.println("控制其11方法执行"+this.users.getPassword());

if ("root".equals(this.users.getUsername())&&"root".equals(this.users.getPassword())) {
return "success" ;
} else {
this.addFieldError("username", "用户名或密码错误") ;
return "input" ;
}
}

public String login2 () throws Exception {
System.out.println("控制其22方法执行"+this.users.getPassword());

if ("root".equals(this.users.getUsername())&&"root".equals(this.users.getPassword())) {
return "success" ;
} else {
this.addFieldError("username", "用户名或密码错误") ;
return "input" ;
}
}

public void validate() {
System.out.println("验证方法执行"+this.users.getPassword());
if ("".equals(users.getUsername())||null==users.getUsername()) {
this.addFieldError("users.username","用户名不能为空") ;
}
if ("".equals(users.getPassword())||null==users.getPassword()) {
this.addFieldError("users.password","密码不能为空") ;
}
}
}


...全文
503 1 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
桐柏小仙 2010-10-21
呵呵,谢谢了,问题解决了。我把namespace直接去了,


<package name="struts2" extends="struts-default">
<action name="*login" name="*loginDo" class="com.test.action.LoginAction">
<result name="success">welcome.jsp</result>
<result name="fail">regist.jsp</result>
<result name="input">index.jsp</result>

</action>


<!-- 定义多动作控制器方法二 -->
<action name="*loginDo" method="{1}" class="com.zpj.action.LoginAction">
<result name="ok">/success.jsp</result>
<result name="saveUserOk">/success.jsp</result>
<result name="checkUserOk">/success.jsp</result>
<result name="input" type="redirect">/index.jsp</result>
</action>

</package>



就这样把配置文件和jsp页面相应都改了改,就好了
回复
duben4814 2010-10-16


帮忙顶一下!
struts.xml配置错误,找不到"login"对应的配置,
在错误栈中提示 “in namespace: ''” 应该是in namespace: '/' 才是正确的吧,
你把 <s:form action="login" method="post">里面加个路径试试看:加namespace="/"

回复
桐柏小仙 2010-10-16
怎么还没有人回复呢?
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2010-10-16 10:11
社区公告
暂无公告