editstudent2action.java

来自「学校的课程管理及选课系统」· Java 代码 · 共 56 行

JAVA
56
字号
/*
 * 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.wangsong.dao.DAOFactory;
import org.wangsong.dao.StudentDAO;
import org.wangsong.domain.Student;
import org.wangsong.struts.form.EditStudent2Form;

public class EditStudent2Action extends Action
{
	private StudentDAO stuDao;

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

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	{
		EditStudent2Form editForm = (EditStudent2Form) form; 
															 
		String id = (String) request.getParameter("student_id");	 
		stuDao = this.getStudentDAO();
		Student stu = stuDao.getStudentByID(id);
		stu.setPassword(editForm.getPassword());
		stu.setTel(editForm.getTel());
		stu.setEmail(editForm.getEmail());
		ActionMessage message = null;
		ActionMessages messages = null;

		if (stuDao.updateStudent(stu))
		{
			message = new ActionMessage("学生信息更新成功!!!",false);
			messages = new ActionMessages();
			messages.add("editSuccess", message);
			saveErrors(request, messages);

			return (mapping.findForward("success"));
		}

		return (mapping.getInputForward());

	}
}

⌨️ 快捷键说明

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