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

📄 teacherloginaction.java

📁 struts在线考试系统. 自己还没看
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -