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

📄 studentaction.java

📁 学校的课程管理及选课系统
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package org.wangsong.struts.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 org.apache.struts.util.ModuleException;
import org.wangsong.dao.DAOFactory;
import org.wangsong.dao.StudentDAO;
import org.wangsong.domain.Student;
import org.wangsong.exception.StudentIdExistException;
import org.wangsong.service.UserExistJudgedService;
import org.wangsong.struts.form.StudentForm;

public class StudentAction extends Action
{

	private StudentDAO stuDao;

	public StudentDAO getStudentDAO()
	{
		return DAOFactory.getInstance().createStudentDAO();
	}

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)throws ModuleException
	{

		StudentForm stuForm = (StudentForm) form;

		stuDao = this.getStudentDAO();
		UserExistJudgedService uej= new UserExistJudgedService();

		Student stu = new Student();
 		stu.setId(stuForm.getId());
		stu.setName(stuForm.getName());
		stu.setDepartment(stuForm.getDepartment());
		stu.setPassword(stuForm.getPassword());
		stu.setSex(stuForm.getSex());
		stu.setJiguan(stuForm.getJiguan());
         
		try
		{
			uej.studentIdExist(stu.getId());
		}
		catch (StudentIdExistException e)
		{
			 throw new ModuleException("error.addstu.user.exist");
			
		} 
		ActionMessage message=null;
		ActionMessages messages=null;
		if (stuDao.saveStudent(stu))
		{
			message=new ActionMessage("page.addstu.student.add.success");
			messages=new ActionMessages();
			messages.add("addstudent",message);
			saveErrors(request,messages);
			return (mapping.findForward("success"));
		}
		message=new ActionMessage("page.addstu.student.add.failure");
		messages=new ActionMessages();
		messages.add("addstudent",message);
		saveErrors(request,messages);

		 return (mapping.getInputForward());
	}
}

⌨️ 快捷键说明

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