package com.tes.action;
import java.math.BigDecimal;
import java.sql.Date;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
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.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.actions.DispatchAction;
import com.tes.bean.Book;
import com.tes.bean.Course;
import com.tes.bean.Point;
import com.tes.bean.Section;
import com.tes.bean.Teacher;
import com.tes.exception.NoBooksExistException;
import com.tes.exception.NoPointExistException;
import com.tes.exception.NoSectionExistException;
import com.tes.exception.NoStudentEvaluateException;
import com.tes.exception.PeopleNotExistException;
import com.tes.service.iface.IStudentService;
import com.tes.service.iface.ITeacherService;
public class TeacherAction extends DispatchAction{
private ITeacherService teacherService;
private IStudentService studentService;
public ActionForward teacherLogin(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
//建立DynaDynaActionForm对象,用于从获取表单中的内容
DynaActionForm dform = (DynaActionForm)form;
//获得教师输入的姓名和身份证号
String teacherName = dform.getString("teacherName");
String idcard = dform.getString("idcard");
try {
Teacher teacher = new Teacher();
//对教师登陆进行验证
teacher = teacherService.teacherLogin(teacherName,idcard);
//如果验证通过,将跳转到教师操作页面,验证失败将产生异常
request.getSession().setAttribute("teacherId",teacher.getId());
return mapping.findForward("TeacherView");
} catch (PeopleNotExistException e) {
//建立ActionMessages对象
ActionMessages errors = new ActionMessages();
//将异常或错误信息存入ActionMessages对象errors中
errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("error.peopleNotExist"));
//把ActionMessages对象存入到request对象中
saveErrors(request,errors);
//跳转到错误处理页面
return mapping.findForward("TeacherLogin");
}
}
public ActionForward goTeachedCourseView(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
//从Session对象中获得教师对象的OID
Integer teacherId = (Integer)request.getSession().getAttribute("teacherId");
//建立课程列表对象
List courseList = new ArrayList();
//根据教师对象OID获得该教师所授课程列表
courseList = teacherService.teachedCourse(teacherId);
//将课程列表对象和教师OID存入Request对象中
request.setAttribute("courseList",courseList);
request.setAttribute("teacherId",teacherId);
//跳转到显示教师所授课程的页面
return mapping.findForward("TeachedCourseView");
}
public ActionForward goCreateCourse(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
//从Session对象中获得教师对象的OID
Integer teacherId = (Integer)request.getSession().getAttribute("teacherId");
//建立教材列表对象
List bookList = new ArrayList();
//获得所有的教材
bookList = studentService.getAllBooks();
//将教材列表对象和教师对象分别存入到Request对象中
request.setAttribute("bookList",bookList);
request.setAttribute("teacherId",teacherId);
//跳转到建立课程页面
return mapping.findForward("CreateCourse");
}
public ActionForward modifyCourse(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
Integer courseId ;
//如果从Request对象中不能获得课程对象OID,就从Session对象中获得课程对象的OID
if(request.getParameter("courseId")!=null){
courseId =Integer.valueOf(request.getParameter("courseId"));
}else{
courseId =(Integer) request.getSession().getAttribute("courseId");
}
//根据课程对象OID获得课程对象
Course course = new Course();
course = studentService.getCourse(courseId);
//根据课程对象OID获得课程包含的所有教材列表
List bookList = studentService.getBooks(courseId);
//将教材列表和课程对象存入Request对象中,用于页面显示
request.setAttribute("bookList",bookList);
request.setAttribute("course",course);
//将课程对象OID存入Session对象中
request.getSession().setAttribute("courseId",courseId);
//跳转到修改课程页面
return mapping.findForward("ModifyCourse");
}
public ActionForward saveCourse(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
//从页面表单中获得课程的相关输入信息
DynaActionForm dform = (DynaActionForm)form;
String courseName = dform.getString("courseName");
Integer courseNumber = Integer.valueOf(dform.getString("courseNumber"));
String courseDescription = dform.getString("courseDescription");
//建立课程对象,并把从表单中获得的课程信息存入课程对象
Course course = new Course();
course.setName(courseName);
course.setCourseNumber(courseNumber);
course.setDescription(courseDescription);
//从页面中获得教师对象OID
Integer teacherId =(Integer) request.getSession().getAttribute("teacherId");
//从页面中获得教师建立课程时所选的教材
String[] bookIds = request.getParameterValues("bookIds");
//保存课程对象
teacherService.saveCourse(teacherId,course,bookIds);
//建立课程列表对象
List courseList = new ArrayList();
//获得教师所授课程列表
courseList = teacherService.teachedCourse(teacherId);
//把课程列表存入Request对象中
request.setAttribute("courseList",courseList);
//跳转到教师查看所授课程的页面
return mapping.findForward("TeachedCourseView");
}
public ActionForward updateCourse(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
//从页面表单中获得修改后的课程信息
DynaActionForm dform = (DynaActionForm)form;
String courseName = dform.getString("courseName");
String courseDescription = dform.getString("courseDescription");
Integer courseNumber =Integer.valueOf(dform.getString("courseNumber"));
//从Session对象中获得课程对象OID
Integer courseId = (Integer)request.getSession().getAttribute("courseId");
//修改课程对象中各个属性
Course course = new Course();
course = studentService.getCourse(courseId);
course.setName(courseName);
course.setDescription(courseDescription);
course.setCourseNumber(courseNumber);
//更新课程对象
studentService.updateCourse(course);
//根据Session对象中的教师OID,获得教师所授课程列�
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Java EE开发指南—基于Spring/Struts/Hibernate的实现 源码(第二部分) (275个子文件)
TeacherAction.class 16KB
StudentServiceImpl.class 8KB
studentLogin_jsp.class 8KB
TeacherServiceImpl.class 8KB
StudentPointDAOTest.class 7KB
TeacherServiceTest.class 6KB
StudentAction.class 6KB
basePage_jsp.class 6KB
menu_jsp.class 5KB
BaseStudent.class 5KB
StudentServiceTest.class 5KB
footer_jsp.class 5KB
BaseBook.class 5KB
ManagerAction.class 5KB
index_jsp.class 5KB
StudentPointDAOImpl.class 5KB
BaseCourse.class 5KB
BaseTeacher.class 4KB
PointDAOTest.class 4KB
BasePoint.class 4KB
TeacherDAOTest.class 4KB
BaseSection.class 4KB
StudentDAOTest.class 4KB
BookDAOTest.class 3KB
CourseDAOTest.class 3KB
BaseStudentPoint.class 3KB
ManagerServiceImpl.class 3KB
StudentDAOImpl.class 3KB
PointDAOImpl.class 3KB
header_jsp.class 3KB
CourseDAOImpl.class 2KB
TeacherDAOImpl.class 2KB
BaseStudentCourse.class 2KB
BookDAOImpl.class 2KB
CourseDAOImpl$1.class 2KB
IStudentService.class 1KB
SectionDAOImpl.class 1KB
ITeacherService.class 1KB
EncodingProcessor.class 977B
Book.class 879B
Student.class 849B
StudentPoint.class 815B
IStudentPointDAO.class 799B
Teacher.class 751B
testMaths.class 735B
Point.class 731B
Section.class 730B
Course.class 712B
IStudentDAO.class 603B
StudentCourse.class 571B
IManagerService.class 486B
ITeacherDAO.class 448B
ICourseDAO.class 430B
IBookDAO.class 395B
IPointDAO.class 369B
NoStudentEvaluateException.class 342B
PeopleNotExistException.class 333B
NoSectionExistException.class 333B
NoBooksExistException.class 327B
NoPointExistException.class 327B
ISectionDAO.class 296B
.classpath 5KB
.cvsignore 7B
.cvsignore 4B
spring-beans.dtd 21KB
tiles-config.dtd 2KB
spring.ftl 11KB
hibernate3.jar 1.88MB
spring.jar 1.84MB
jgroups-2.2.8.jar 1.54MB
ant-1.6.5.jar 1010KB
xerces-2.6.2.jar 987KB
hibernate2.jar 928KB
jboss-jmx.jar 578KB
jboss-common.jar 570KB
struts.jar 531KB
c3p0-0.9.0.jar 476KB
proxool-0.8.3.jar 465KB
antlr-2.7.6rc1.jar 434KB
spring-beans.jar 380KB
jboss-cache.jar 366KB
antlr.jar 350KB
log4j-1.2.11.jar 342KB
dom4j-1.6.1.jar 307KB
spring-aop.jar 296KB
spring-webmvc.jar 277KB
cglib-2.1.3.jar 276KB
cglib-2.1.jar 275KB
mysql-connector-java-3.1.6-bin.jar 230KB
jaxen-1.1-beta-7.jar 222KB
spring-jdbc.jar 222KB
jboss-system.jar 218KB
commons-lang-2.1.jar 203KB
spring-hibernate.jar 190KB
commons-beanutils.jar 184KB
spring-orm.jar 177KB
spring-core.jar 176KB
commons-collections-2.1.1.jar 171KB
concurrent-1.3.2.jar 167KB
commons-digester.jar 164KB
共 275 条
- 1
- 2
- 3
资源评论
- shy1292012-12-24这东西有一定价值
- 好名字占了2012-12-18东西还是有一定价值的!
迷途小黄牛
- 粉丝: 8
- 资源: 42
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功