- 博客(0)
- 资源 (2)
空空如也
实践考核类课二 选课系统
东北大学 实践考核类课二 选课系统
public class ChooseClass extends HttpServlet {
private static final Log log = LogFactory.getLog(ChooseClass.class);
/**
* Constructor of the object.
*/
public ChooseClass() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
HttpSession session=request.getSession(true);
String stuid=(String) session.getAttribute("usr");
String[] list=request.getParameterValues("chooselist");
for(int count=0;count<list.length;count++){
StudentDAO stu=new StudentDAO();
Student student=new Student();
Beans.ChooseClass choose=new Beans.ChooseClass();
student=stu.findById(stuid);
ClassesDAO cla=new ClassesDAO();
Classes classes=new Classes();
ChooseClassDAO cho=new ChooseClassDAO();
classes=cla.findById(list[count]);
choose.setClasses(classes);
choose.setStudent(student);
cho.save(choose);
ClassesDAO cladao=new ClassesDAO();
Classes clas=choose.getClasses();
int num=clas.getNumOfStu();
clas.setNumOfStu(num-1);
cladao.attachDirty(clas);
}
log.info("选课成功");
response.sendRedirect("choosesuc.jsp");//选课成功页面
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
2012-03-25
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人