方式一
編寫Action方法
package action;
import com
public class LoginAction extends ActionSupport{
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this
}
@Override
public String execute() throws Exception {
if (
return
}else {
return
}
}
}
配置文件
<action name=
<result name=
<result name=
<result name=
</action>
然後編寫登錄的JSP頁面
<s:form action=
<table width=
<tr>
<td>
<s:textfield key=
</td>
</tr>
<tr>
<td>
<s:password key=
</td>
</tr>
<tr>
<td>
<s:submit value=
</td>
</tr>
</table>
</s:form>
注意這裡面的JSP裡面的表單名稱要與Action裡面的名稱保持一致的
也可以將其抽出來/
方式二
自定義vo文件名
文件內容
package struts
public class LoginVO {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this
}
}
在Action文件中
文件內容
package struts
public class LoginAction {
private LoginVO user = null;
public String execute() {
System
if (user
user
return
}
else {
return
}
}
public LoginVO getUser() {
return user;
}
public void setUser(LoginVO user) {
this
}
}
登陸成功的文件如下
<%@ page contentType=
<%@ taglib uri=
<meta http
歡迎您
注意login文件的部分也要進行修改
文件內容如下
<meta http
<title>login
<form action=
username:<input type=
password:<input type=
<input type=
</form>
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26891.html