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

📄 teacherlogaction.java

📁 使用struts+spring+JDBC 实现的学生选课管理系统
💻 JAVA
字号:
package bit.jeffy.action;

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

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import bit.jeffy.bean.TeacherLoger;
import bit.jeffy.entity.Teacher;
import bit.jeffy.service.TeacherDao;

public class TeacherLogAction extends Action{
	private TeacherDao teacherdao;
	
	public ActionForward execute(ActionMapping map, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		// TODO 自动生成方法存根
		ActionMessages errors = new ActionMessages();
		
		String path = servlet.getServletContext().getRealPath("/WEB-INF/beans.xml");
		String rp = (String)request.getSession().getAttribute("path");
		if(rp != null){
			request.getSession().removeAttribute("path");
		}
		request.getSession().setAttribute("path",path);
		
		String username = (String)((TeacherLoger)form).getZh();
		String password = (String)((TeacherLoger)form).getPassword();
		username = new String(username.getBytes("ISO-8859-1"),"GB2312");
		password = new String(password.getBytes("ISO-8859-1"),"GB2312");

		if( username.equals("") || password.equals("")){
			errors.add("fail_1",new ActionMessage("TeacherLogAction.a"));
			saveErrors(request,errors);
			return (map.getInputForward());
		}
		
		HttpSession session = request.getSession();
		Teacher tea = new Teacher();
		Teacher t = null;
		tea.setTh(username);
		tea.setPassword(password);
		String tmp = null;
		
	
		t = teacherdao.read(tea);
		if( t != null)
		{
			tmp = (String)session.getAttribute("curr_tea_th");
			if( tmp == null)
			{
				session.setAttribute("curr_tea_id",new Long(t.getId()));
				session.setAttribute("curr_tea_th",username);
			}
			else
			{
				session.removeAttribute("curr_tea_id");
				session.removeAttribute("curr_tea_th");
				session.setAttribute("curr_tea_id",new Long(t.getId()));
				session.setAttribute("curr_tea_th",username);
			}
			return (map.findForward("login"));
		}
		else
		{
			errors.add("fail_3",new ActionMessage("TeacherLogAction.b"));
			saveErrors(request,errors);
			return (map.getInputForward());
		}
	}
	public TeacherDao getTeacherdao() {
		return teacherdao;
	}
	public void setTeacherdao(TeacherDao teacherdao) {
		this.teacherdao = teacherdao;
	}

}

⌨️ 快捷键说明

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