登陆界面:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action=success>
<label align="left" for="user">用户名:<input type=text name="user" name="user" id="user"></label><p></p>
<label align="left" for="password">密码 :<input type=password name="password" id="password" name="password"></label><P></P>
<input type=submit value="登陆"> <input type="reset" value="重置">
</form>
</body>
</html>
form表单action属性提交到success,配置文件里面name值与之对应,class表示提交到的处理类,method指定处理方法,当没有method值时,会用默认方法execute替代,result里面的name值对应LoginAction返回值
<action name="success" class="com.chen.Action.LoginAction" method="login" >
<result name="success">/success.jsp</result>
<result name="error">/error.jsp</result>
<result name="user">/user.jsp</result>
</action>
LoginAction类代码
public class LoginAction extends ActionSupport {
private String user;
private String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("成功登陆");
return "success";
}
public String login(){
if(user.equals("chen")){
if(password.equals("1234")){
return "success";
}
return "error";
}
return "error";
}
}