courseaction.java
来自「java 框架核心技术编程」· Java 代码 · 共 174 行
JAVA
174 行
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package org.lxh.struts.action;
import java.util.List;
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 org.apache.struts.actions.DispatchAction;
import org.lxh.factory.DAOFactory;
import org.lxh.struts.form.CourseForm;
import org.lxh.vo.Course;
/**
* MyEclipse Struts Creation date: 06-14-2007
*
* XDoclet definition:
*
* @struts.action path="/course" name="courseForm" input="/form/course.jsp"
* parameter="status" scope="request" validate="true"
*/
public class CourseAction extends DispatchAction {
/*
* Generated Methods
*/
/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward insert(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
CourseForm courseForm = (CourseForm) form;
Course c = new Course();
c.setName(courseForm.getName());
c.setTeacher(courseForm.getTeacher());
c.setCreditHour(Integer.parseInt(courseForm.getCreditHour()));
try {
DAOFactory.getCourseDAOInstance().insert(c);
} catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward("insertdo");
}
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
CourseForm courseForm = (CourseForm) form;
try {
DAOFactory.getCourseDAOInstance().delete(
Integer.parseInt(courseForm.getCid()));
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mapping.findForward("deletedo");
}
public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
CourseForm courseForm = (CourseForm) form;
Course c = new Course();
c.setCid(Integer.parseInt(courseForm.getCid()));
c.setName(courseForm.getName());
c.setTeacher(courseForm.getTeacher());
c.setCreditHour(Integer.parseInt(courseForm.getCreditHour()));
try {
DAOFactory.getCourseDAOInstance().update(c);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mapping.findForward("updatedo");
}
public ActionForward selectid(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
CourseForm courseForm = (CourseForm) form;
Course c = null;
try {
c = DAOFactory.getCourseDAOInstance().queryByCId(
Integer.parseInt(courseForm.getCid()));
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.setAttribute("course", c);
return mapping.findForward("update");
}
public ActionForward selectcoursestudent(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
// System.out.println("--------------------") ;
CourseForm courseForm = (CourseForm) form;
Course c = null;
try {
c = DAOFactory.getCourseDAOInstance().queryByCId(
Integer.parseInt(courseForm.getCid()));
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("course", c);
return mapping.findForward("liststudent");
}
public ActionForward selectall(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
List all = null;
try {
all = DAOFactory.getCourseDAOInstance().queryAll();
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("all", all);
return mapping.findForward("list");
}
public ActionForward choosecourse(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
List all = null;
try {
all = DAOFactory.getCourseDAOInstance().queryAll();
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("all", all);
return mapping.findForward("choosecourse");
}
public ActionForward selectlike(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
List all = null;
try {
all = DAOFactory.getCourseDAOInstance().queryByLike(
request.getParameter("keyWord"));
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("all", all);
return mapping.findForward("list");
}
public ActionForward cancelchoosecourse(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
try {
int cid = Integer.parseInt(request.getParameter("cid"));
int sid = Integer.parseInt(request.getParameter("sid"));
Course c = DAOFactory.getCourseDAOInstance().queryByCId(cid) ;
c.getSids().remove(new Integer(sid)) ;
DAOFactory.getCourseDAOInstance().update(c) ;
} catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward("cancelchoosecourse");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?