日期:2014-05-19  浏览次数:20747 次

眼尖的来看看吧。我快崩溃了。struts2简单配置
本帖最后由 AA5279AA 于 2013-01-25 13:59:55 编辑
做一个小项目,本来没问题。
后来换了个一个开发编辑工具,就开始出问题了。。
大家帮忙看看问题出在哪了吧?
今天遇到的问题太多,头痛,实在解决不了了。
下面是简化的,登陆页面:
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="login" method="get">
姓名:<input name="name" type="text"></input><br>
密码:<input name="password" type="password"></input><br>
<input type="submit" value="注册"></input>
</form>
</body>
</html>

下面是struts配置:
<package name="myPackage" namespace="/resources" extends="base">
<!-- <default-class-ref class=""/> -->
<global-results>
<result name="success">/resources/loginsuccess.jsp</result>
<result name="error">/resources/error.html</result>

</global-results>
<action name="login" method="logins" class="cn.test.springTest.LoginAction">

</action>
<action name="register" method="execute" class="cn.test.springTest.RegisterAction">

</action>

</package>

下面就是action层了。

public class LoginAction extends ActionSupport{
String name;
String password;
public String logins(){


//ActionContext ac = ActionContext.getContext();

HttpServletRequest request=ServletActionContext.getRequest();
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.setAttribute("name", name);
request.setAttribute("password", password);
System.out.println("in login");

if((name!=null)&&(password!=null)){
System.out.println("用户信息已经接受");
System.out.println("用户名为"+name+",密码为:"+password);
return SUCCESS;

}else{
System.out.println("用户名或者密码为空");
return ERROR;
}

}




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

}

出现问题:logins()这个方法不运行。。。
页面也不报错,页面的过滤问题好像被我的过滤器给过滤了。
求帮忙。
报错信息:WARN : org.apache.struts2.dispatcher.Dispatcher - Could not find action or result
There is no Action mapped for action name login. - [unknown location]

------解决方案--------------------
form的action地址不是login
<form action="login.action" method="get"> 
------解决方案--------------------
<form action="login!logins" method="get">    这样试试
-