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

📄 loginaction.java

📁 出试卷系统(包括前台教师出卷系统
💻 JAVA
字号:
package action;

import java.util.Enumeration;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.MappingDispatchAction;

import entity.Student;
import entity.Teacher;
import forms.LoginForm;
import biz.LoginBIZ;


public class LoginAction extends MappingDispatchAction{
	private LoginBIZ loginbiz;
	public ActionForward login(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		   	LoginForm loginForm = (LoginForm) form;
			System.out.println("********88");
			//System.out.println(loginbiz);
		   	System.out.println("********88"+loginForm.getLogin_name());
			System.out.println("********88"+loginForm.getLogin_password());
			Teacher teacher = null;
			Student student = null;
			HttpSession session = request.getSession(false);
			if (loginForm.getType()>0) // 1 is teacher
			{
				System.out.println("********88"+loginForm.getType());
				teacher = (Teacher)loginbiz.teacherLogin(loginForm.getLogin_name(),loginForm.getLogin_password());
				
			}
			else // 0 is Administrator
			{
				student = (Student) loginbiz.studentLogin(
						loginForm.getLogin_name(), loginForm.getLogin_password());
				if (student == null) {
					return mapping.findForward("index");
				}
				session.setAttribute("student", student);
				return mapping.findForward("success");
			}
			System.out.println(teacher);
			session.setAttribute("Teacher",teacher);
			Teacher t=(Teacher) session.getAttribute("Teacher");
		    //System.out.println("********88"+t.getLogin_name());
			return mapping.findForward("success");
	}
	public void setLoginbiz(LoginBIZ loginbiz) {
		this.loginbiz = loginbiz;
	}
	public ActionForward logout(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		HttpSession session = request.getSession(false);

		Enumeration attrs = session.getAttributeNames();
		while (attrs.hasMoreElements())
		{
			session.removeAttribute((String) attrs.nextElement());
		}

		session.invalidate();
		return mapping.findForward("index");
	}	
	
}

⌨️ 快捷键说明

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