useraction.java

来自「一个简单的java邮件系统源码」· Java 代码 · 共 55 行

JAVA
55
字号
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 + =
减小字号Ctrl + -
显示快捷键?