📄 useraction.java
字号:
package com.easyjweb.action;
import com.easyjf.web.Globals;
import com.easyjf.web.IWebAction;
import com.easyjf.web.Module;
import com.easyjf.web.Page;
import com.easyjf.web.WebForm;
import com.easyjweb.business.User;
import com.easyjweb.business.UserManage;
/**
* 直接实现IWebAction接口实现的EasyJWeb Action,当一个action要处理很多命令的时候,将会显得比较复杂。这种情况我们推荐使用命令模式的抽象类AbstractCmdAction来实现
* @author Administrator
*
*/
public class userAction implements IWebAction {
public Page execute(WebForm form, Module module) throws Exception {
String command = (String) form.get("easyJWebCommand");
if ("reg".equals(command)) {
return new Page("reg", "/userReg.html", Globals.PAGE_TEMPLATE_TYPE);
} else if ("save".equals(command)) {
User user = (User) form.toPo(User.class);
if (user.save()) {
form.addResult("msg", "用户注册成功!");
return new Page("login", "/userLogin.html",
Globals.PAGE_TEMPLATE_TYPE);
} else {
form.addResult("msg", "用户注册失败,用户名、密码及Email不能为空!");
return new Page("reg", "/userReg.html",
Globals.PAGE_TEMPLATE_TYPE);
}
} else if ("login".equals(command))// 提交登录信息
{
String userName = (String) form.get("userName");
String password = (String) form.get("password");
User user = UserManage.simpleLogin(userName, password);
if (user != null)// 登录成功
{
form.addResult("user", user);
return new Page("success", "/userLoginResult.html",
Globals.PAGE_TEMPLATE_TYPE);
} else// 用户名或者密码错误
{
form.addResult("msg", "登录失败,用户名或者密码不正确!");
return new Page("login", "/userLogin.html",
Globals.PAGE_TEMPLATE_TYPE);
}
} else {
// 进入登录
return new Page("login", "/userLogin.html",
Globals.PAGE_TEMPLATE_TYPE);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -