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

📄 addteacheraction.java

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

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

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.NewTeacher;
import bit.jeffy.entity.Teacher;
import bit.jeffy.service.TeacherDao;

public class AddTeacherAction extends Action {

	private TeacherDao teacherdao;
	
	public ActionForward execute(ActionMapping map, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		// TODO 自动生成方法存根
		ActionMessages errors = new ActionMessages();
		String xh = (String)((NewTeacher)form).getTh();
		String password = (String)((NewTeacher)form).getPassword();
		String password_ag = (String)((NewTeacher)form).getPassword_ag();
		String xm = (String)((NewTeacher)form).getXm();
		String yx = (String)((NewTeacher)form).getYx();
		xh = new String(xh.getBytes("ISO-8859-1"),"GB2312");
		password = new String(password.getBytes("ISO-8859-1"),"GB2312");
		password_ag = new String(password_ag.getBytes("ISO-8859-1"),"GB2312");
		xm = new String(xm.getBytes("ISO-8859-1"),"GB2312");
		yx = new String(yx.getBytes("ISO-8859-1"),"GB2312");
		
		if(xh == null || xh.equals("")){
			errors.add("fail_1",new ActionMessage("AddStudentAction.a"));
			saveErrors(request,errors);
			return (map.getInputForward());
		}
		if(password == null || password.equals("")){
			errors.add("fail_2",new ActionMessage("AddStudentAction.b"));
			saveErrors(request,errors);
			return (map.getInputForward());
		}
		if(!password.equals(password_ag)){
			errors.add("fail_4",new ActionMessage("AddStudentAction.c"));
			saveErrors(request,errors);
			return (map.getInputForward());
		}
		
		Teacher tea = new Teacher();
		tea.setTh(xh);
		tea.setPassword(password);
		tea.setXm(xm);
		tea.setYx(yx);
		
		if(teacherdao.validate(tea)){
			errors.add("fail_5",new ActionMessage("AddStudentAction.d"));
			saveErrors(request,errors);
			return (map.getInputForward());
		}
		
		if(teacherdao.save(tea)){
			return (map.findForward("addok"));
		}else{
			errors.add("fail_6",new ActionMessage("AddStudentAction.e"));
			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 + -