日期:2014-05-19 浏览次数:20800 次
<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>
<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>
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;
}
}