teacherloginaction.java

来自「struts在线考试系统. 自己还没看」· Java 代码 · 共 62 行

JAVA
62
字号
package com.lili.exam.action;

import org.apache.struts2.ServletActionContext;

import com.lili.common.exception.ExamException;
import com.lili.exam.pojo.Teacher;
import com.lili.exam.service.ExamService;
import com.lili.exam.service.ExamServiceImpl;
import com.lili.exam.util.BeanFactory;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class TeacherLoginAction extends ActionSupport implements Action{
	private String name;
	private String password;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	public String execute(){
		ExamService service = (ExamServiceImpl)BeanFactory.getBean("examService");
		String passwd = null;
		try {
			
			Teacher teacher = service.getTeacherByName(name);
System.out.println(teacher+" : ");
			passwd = teacher.getPassword();
			if(passwd.equals(password)){
				return SUCCESS;
			}else {
				ServletActionContext.getRequest().setAttribute("message","�û��������������密码错误!");
				return ERROR;
			}
		}catch(Exception ex){
			ex.printStackTrace();
			ServletActionContext.getRequest().setAttribute("message","用户名或密码有误!");
			return INPUT;
		}
	}
	public void validate() {
		
		if (name == null && name.trim().length() == 0) {
			this.addFieldError("name", "�û�����用户名不能为空!");
		}
		if (password == null & password.trim().length() == 0) {
			this.addFieldError("password", "���密码不能为空!�գ�");
		}
		System.out.println("============== validate =========");
		
	}
}

⌨️ 快捷键说明

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