首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

眼尖的来看看吧。小弟我快崩溃了。struts2简单配置

2013-02-19 
眼尖的来看看吧。我快崩溃了。struts2简单配置本帖最后由 AA5279AA 于 2013-01-25 13:59:55 编辑做一个小项

眼尖的来看看吧。我快崩溃了。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">    这样试试
[解决办法]
在struts配置文件配置了namespace="/resources",<form action="login" method="get">应该要指定namespace才对,不然默认是到namespace=“/”里面找吧?是不是这样?


[解决办法]

引用:
引用:form的action地址不是login
<form action="login.action" method="get">
我的struts.xml中也是login,加或者不加效果都是一样的。。
<action name="login" method="logins" class="cn.test.springTest.Log……

不加找不到action的即使你在web.xml里配置的url-pattern是什么
[解决办法]
你用/*可以不加.action确保你当前这jsp的路径是不是在/resources下
[解决办法]
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="/resources/login.action" method="get">
姓名:<input name="name" type="text"></input><br>
密码:<input name="password" type="password"></input><br>
<input type="submit" value="注册"></input>
</form>
</body>
</html>

<form action="/resources/login.action" method="get">
[解决办法]
我以前遇到这样的问题,怎么看都是没错的,在jsp页面中,Form中的action="Login" 对应的struts.xml中<action name="Login"..>
Action首字母大写可避免此问题,我的是这样的问题。
[解决办法]
post 提交看看呢
[解决办法]
我会告诉你我搭建ssh时候因为jsp上没写s得taglib 纠结了一周得时间么

热点排行