📄 loginaction.java
字号:
package cn.com.pkusoft.action.login;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.com.pkusoft.action.BaseAction;
import cn.com.pkusoft.comm.CommException;
import cn.com.pkusoft.control.BaseControl;
import cn.com.pkusoft.control.login.LoginControl;
public class LoginAction
extends BaseAction
{
private List userList_ = null;
protected void doInit()
{
//在这里可以做一些初始化的工作。
//可以根据从不同的页面过来的而做不同的初始化工作
System.out.println("--------do same initialize here! ");
//模拟一下数据, 在实际的开发中,根据具体的情况来决定。
//1、取得控制对象
LoginControl lc = (LoginControl)this.getCaseControl();
//2、取得数据
userList_ = lc.prepareUser();
}
/**
* 这个方法暂时不需要,以后如果是大项目可以采用工厂模式
* @return BaseAction
*/
public BaseAction getInstance()
{
/**@todo Implement this cn.com.pkusoft.action.BaseAction abstract method*/
throw new java.lang.UnsupportedOperationException("Method getInstance() not yet implemented.");
}
protected void doExecute()
{
//这里主要是做业务逻辑了。
//但不要在这里写业务实现代码,最好是调用业务逻辑的子类来实现。
System.out.println("--------do same execute here! ");
String userid = this.m_request.getParameter("userid");
String passwd = this.m_request.getParameter("password");
Map loginResultMap = new HashMap();
loginResultMap.put("userid",userid);
loginResultMap.put("password",passwd);
this.m_request.getSession().setAttribute("logins" , loginResultMap);
try
{
if (this.m_fromPage.equals("login")) //是从login页面过来的
{
if (this.m_event.equals("E_LOGIN")) //如果是登陆事件
{
if (this.userList_.contains(userid))
{
if (!userid.equals(passwd))
{
//1.密码不对, 添加错误提示信息到页面上 显示
this.putErrorMessage("密码不对!");
//2.设定好要显示的页面
this.m_nextPage = "/login.jsp";
}
else
{
//1.取得控制类对象。
LoginControl lc = (LoginControl)this.getCaseControl();
//2.准备好要显示的数据结果集
List resultList = lc.prepareData();
//3.把要显示的结果集放到SESSION当中,显示出来
this.m_request.getSession().setAttribute("testloop", resultList);
//4.设定好要显示的页面
this.m_nextPage = "/loginOk.jsp";
this.m_request.getSession().setAttribute("USER", userid);
}
}
else
{
//1.用户不存在, 添加错误提示信息到页面上 显示
this.putErrorMessage("用户不存在!");
//2.设定好要显示的页面
this.m_nextPage = "/login.jsp";
}
// 派发到具体的网页中去。
this.dispatchNextPage(m_nextPage);
}
}
}
catch (CommException ex)
{
ex.printStackTrace();
}
}
/**
* 创建一个与LoginAction对应的控制对象实例
* @return BaseControl LoginControl instance
*/
public BaseControl createControlInstance()
{
//创建一个与ACTION对应的控制对象实例
LoginControl loginCtrl = new LoginControl();
return loginCtrl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -