⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginaction.java

📁 当下流行的struts2的一个简单应用
💻 JAVA
字号:
package com.jack.user.action;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.apache.struts2.interceptor.SessionAware;

import com.jack.user.model.IUserServices;
import com.jack.user.pojo.User;
import com.jack.user.pojo.UserInfor;

public class LoginAction implements SessionAware {

	private User user;
	private String userName;
	private String password;
	private String name;
	private String email;
	private String age;
	private String sex;
	private String address;
	private String tip;
	private Map session;
	private IUserServices userServices;

	public void setUserServices(IUserServices userServices) {
		this.userServices = userServices;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getUserName() {
		return this.userName;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPassword() {
		return password;
	}

	/**
	 * 用户登录
	 * 
	 * @return
	 * @throws Exception
	 */
	public String userLogin() throws Exception {
		String result = null;
		try {
			boolean flag = userServices.checkUser(this.getUserName(), this
					.getPassword());
			if (flag) {
				result = "success";
			} else {
				this.setTip("<font color='red'>对不起您的帐号或密码有误!</font>");
				result = "noUser";
			}
		} catch (Exception e) {
			this.setTip("<font color='red'>对不起,系统出现故障,请稍后再登录!</font>");
			e.printStackTrace();
			result = "noUser";
		}
		return result;
	}

	public String saveAccount() {
		String result = null;
		try {
			session.put("userName", this.getUserName());
			session.put("password", this.getPassword());
			result = "success";
		} catch (Exception e) {
			e.printStackTrace();
			result = "error";
		}
		return result;
	}

	public String userRegister() {
		String result = "";
		try {
			user = new User();
			String uname = (String) session.get("userName");
			String pwd = (String) session.get("password");
			user.setUserName(uname);
			user.setPassword(pwd);
			//级联关系部分
			Set set = new HashSet();
			System.out.println("得到的真实姓名:" + this.getName());
			UserInfor userInfor = new UserInfor();
			userInfor.setName(this.getName());
			userInfor.setEmail(this.getEmail());
			userInfor.setSex(this.getSex());
			userInfor.setAddress(this.getAddress());
			userInfor.setAge(Integer.parseInt(this.getAge()));
			userInfor.setUser(user);
			set.add(userInfor);
			//设置添加对象
			user.setUserInfors(set);
			userServices.saveUser(user);
			result = "success";
		} catch (Exception e) {
			this.setTip("系统出现故障!");
			result = "error";
			e.printStackTrace();
		}
		return result;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getTip() {
		return tip;
	}

	public void setTip(String tip) {
		this.tip = tip;
	}

	public void setSession(Map session) {
		this.session = session;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getAge() {
		return age;
	}

	public void setAge(String age) {
		this.age = age;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -