81,122
社区成员




public class LoginAction extends BaseAction {
// 用户名
private String userName;
// 姓名
private String name;
// 密码
private String password;
// 登录时
private String loginTime;
// 考号
private String studentNo;
public String getStudentNo() {
return studentNo;
}
public void setStudentNo(String studentNo) {
this.studentNo = studentNo;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getLoginTime() {
return loginTime;
}
public void setLoginTime(String loginTime) {
this.loginTime = loginTime;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
// 管理员登录
@SuppressWarnings("unchecked")
public String login() {
// 根据用户名,返回对象
if ("admin".equals(userName) && "123456".equals(password)) {
ActionContext context = ActionContext.getContext();
// 格式化日期
loginTime = Util.formatDateTime(new Date());
context.getSession().put(Constant.LOGIN_TIME, loginTime);
context.getSession().put(Constant.CURRENT_USER,
new User(userName, password));
return SUCCESS;
}
return INPUT;
}
// 转到登录界面
public String loginout() {
// 销毁用户信息
ActionContext context = ActionContext.getContext();
// 销毁登录时间
context.getSession().remove(Constant.LOGIN_TIME);
// 销毁当前登录用户
context.getSession().remove(Constant.CURRENT_USER);
return INPUT;
}
@SuppressWarnings("unchecked")
// 考生登录
public String loginP() {
if ("1001".equals(studentNo) && "1".equals(password)) {
ActionContext context = ActionContext.getContext();
// 格式化日期
loginTime = Util.formatDateTime(new Date());
context.getSession().put(Constant.LOGIN_TIME, loginTime);
context.getSession().put(Constant.CURRENT_STUDENT,
new Student(studentNo, password));
return "loginPSuccess";
}
return "loginPInput";
}
// 考生退出
// 转到登录界面
public String loginoutP() {
// 销毁用户信息
ActionContext context = ActionContext.getContext();
// 销毁登录时间
context.getSession().remove(Constant.LOGIN_TIME);
// 销毁当前登录用户
context.getSession().remove(Constant.CURRENT_STUDENT);
return "loginPInput";
}
}
<struts>
<!-- 登录模块 -->
<package name="loginout" extends="struts-default" namespace="/admin">
<action name="login" class="com.haiersoft.ph02.web.action.LoginAction">
<result name="success">/admin/main.jsp</result>
<result name="input">/admin/login.jsp</result>
<result name="loginPSuccess">/stu/main.jsp</result>
<result name="loginPInput">/stu/login.jsp</result>
</action>
</package>
</struts>