package com.loan.action; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.struts2.ServletActionContext; import org.apache.struts2.json.annotations.JSON; import net.sf.json.JSONObject; import com.loan.action.base.BaseAction; import com.loan.entity.Person; import com.opensymphony.xwork2.ActionContext; public class LoginAction extends BaseAction { /** * */ private static final long serialVersionUID = 1L; private String u; private String p; private String result; public String getU() { return u; } public void setU(String u) { this.u = u; } public String getP() { return p; } public void setP(String p) { this.p = p; } @JSON() public String getResult() { return result; } public void setResult(String result) { this.result = result; } @Override public String execute() throws Exception { Map session = ActionContext.getContext().getSession(); Map<String,Object> map = new HashMap<String,Object>(); JSONObject json = null; if(mgr.validateName(u,"login")){ int userId = mgr.loginValid(u, p); if(mgr.loginValid(u, p) > 0){ map.put("data_val", "success"); }else{ map.put("data_val", "p_error"); } }else{ map.put("data_val", "u_error"); } json = JSONObject.fromObject(map); result = json.toString();//给result赋值,传递给页面 return SUCCESS ; } /** * 登陆 * @return * @throws Exception */ public String login() throws Exception { HttpServletRequest request=ServletActionContext.getRequest(); HttpSession session=request.getSession(); Map<Object,Object> map = new HashMap<Object,Object>(); map.put("telephone", u); map.put("email", u); List<Person> pList = mgr.getPersonList(map); Person person = pList.get(0); session.setAttribute("person", person); return SUCCESS ; } /** * 退出 * @return * @throws Exception */ public String loginout() throws Exception { System.out.println("--------------------------"); Map session = ActionContext.getContext().getSession(); session.remove("person"); Map<String,Object> map = new HashMap<String,Object>(); JSONObject json = null; map.put("rcode", "1"); json = JSONObject.fromObject(map); result = json.toString();//给result赋值,传递给页面 return SUCCESS ; } }
最近下载更多
JohnAlex LV9
2022年2月19日
wanglinddad LV54
2021年12月5日
1029162867 LV13
2021年9月25日
ericxu1116 LV24
2021年5月20日
ym111111111 LV3
2021年3月18日
王伟杰 LV2
2021年2月25日
clz123456 LV6
2020年12月21日
yguyue LV8
2020年12月15日
ExamplesDYC LV13
2020年11月21日
wxx001 LV10
2020年10月24日
最近浏览更多
WBelong LV7
3月8日
2017143155 LV12
2023年5月22日
泓鼎168 LV19
2023年3月30日
95959595959 LV13
2023年2月13日
upup996 LV6
2022年12月14日
uni-code_0123 LV1
2022年11月16日
maniheim LV7
2022年9月30日
wjh12345654321 LV14
2022年8月2日
折叠门
2022年7月6日
暂无贡献等级
liangge2115 LV27
2022年6月29日