Chào các bạn! Vì nhiều lý do từ nay Truyen2U chính thức đổi tên là Truyen247.Pro. Mong các bạn tiếp tục ủng hộ truy cập tên miền mới này nhé! Mãi yêu... ♥

AddStudentStrutsAction

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package struts;

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.ActionMapping;

import org.apache.struts.action.ActionForward;

import java.util.*;

import data.*;

import java.text.DateFormat;

import java.text.ParseException;

/**

*

* @author Administrator

*/

public class AddStudentStrutsAction extends org.apache.struts.action.Action {

/* forward name="success" path="" */

private final static String SUCCESS = "home";

/**

* This is the action called from the Struts framework.

* @param mapping The ActionMapping used to select this instance.

* @param form The optional ActionForm bean for this request.

* @param request The HTTP Request we are processing.

* @param response The HTTP Response we are processing.

* @throws java.lang.Exception

* @return

*/

public ActionForward execute(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response)

throws Exception {

AddStudentActionForm af = (AddStudentActionForm) form;

StudentDAO sd = new StudentDAO();

Student std = new Student();

std.setFullName(af.getFullName());

std.setMark(af.getMark());

std.setBirthday(parseDate(af.getBirthday()));

sd.insert(std);

return mapping.findForward(SUCCESS);

}

private Date parseDate(String sDate){

try {

return DateFormat.getDateInstance(DateFormat.SHORT, Locale.FRENCH).parse(sDate);

} catch (ParseException ex) {

return null;

}

}

}

Bạn đang đọc truyện trên: Truyen247.Pro

Tags: