addstudentaction.java

来自「通过此代码可实现 学生信息的增删改查」· Java 代码 · 共 40 行

JAVA
40
字号
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.jinshi.struts.action;

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

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.jinshi.struts.bean.Student;
import com.jinshi.struts.form.StudentForm;
import com.jinshi.struts.service.IStudentService;

public class AddStudentAction extends BaseAction {

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		try {
			StudentForm studentForm = (StudentForm) form;

			Student student = new Student();
			student.setStudName(studentForm.getName().trim());
			student.setStudPwd(studentForm.getPassword().trim());
			student.setStudSex(studentForm.getSex().trim());
			student.setStudCol(studentForm.getCol().trim());
			student.setStudClass(studentForm.getClas().trim());
            student.setStudAge(Integer.parseInt(studentForm.getAge()));
			IStudentService service = (IStudentService) getBean("studentService");
			service.addStudent(student);
		} catch (Exception ex) {
			System.out.println("【系统错误】在AddStudentAction中出错,原因是:");
			ex.printStackTrace();
		}
		return new ActionForward("/index.jsp");
	}
}

⌨️ 快捷键说明

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