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

桐柏小仙 桐柏小仙 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
请教各位大师,这个问题怎么解决,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","密码不能为空") ;
}
}
}


...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
桐柏小仙
Web 开发 81,107 成员 341,720 内容