studentlogaction.java

来自「使用struts+spring+JDBC 实现的学生选课管理系统」· Java 代码 · 共 84 行

JAVA
84
字号
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.StudentLoger;
import bit.jeffy.entity.Student;
import bit.jeffy.service.StudentDao;

public class StudentLogAction extends Action{
	
	private StudentDao studentdao;
	
	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)((StudentLoger)form).getZh();
		String password = (String)((StudentLoger)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("StudentLogAction.a"));
			saveErrors(request,errors);
			return (map.getInputForward());
		}
		
		HttpSession session = request.getSession();
		Student stu = new Student();
		Student ts = null;
		stu.setXh(username);
		stu.setPassword(password);
		String tmp = null;
		
		ts = studentdao.read(stu);
		if( ts != null)
		{
			tmp = (String)session.getAttribute("curr_stu_xh");
			if( tmp == null)
			{
				session.setAttribute("curr_stu_id",new Long(ts.getId()));
				session.setAttribute("curr_stu_xh",username);
			}
			else
			{
				session.removeAttribute("curr_stu_id");
				session.removeAttribute("curr_stu_xh");
				session.setAttribute("curr_stu_id",new Long(ts.getId()));
				session.setAttribute("curr_stu_xh",username);
			}
			return (map.findForward("login"));
		}
		else
		{
			errors.add("fail_3",new ActionMessage("StudentLogAction.b"));
			saveErrors(request,errors);
			return (map.getInputForward());
		}
	}
	public StudentDao getStudentdao() {
		return studentdao;
	}
	public void setStudentdao(StudentDao studentdao) {
		this.studentdao = studentdao;
	}
}

⌨️ 快捷键说明

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