package teacherActions;
import java.util.Collection;
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.MappingDispatchAction;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import pojo.Score;
import pojo.Student;
import pojo.Teacher;
import service.StudentService;
import service.TeacherService;
public class TeacherAction extends MappingDispatchAction{
ApplicationContext ac =
new ClassPathXmlApplicationContext("applicationContext.xml");
TeacherService tservice =
(TeacherService) ac.getBean("teacherServiceImpl");
StudentService sservice =
(StudentService) ac.getBean("studentServiceImpl");
public ActionForward teachermessage(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
return mapping.findForward("success");
}
public ActionForward listself(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
return mapping.findForward("success");
}
public ActionForward modifyself(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
return mapping.findForward("success");
}
public ActionForward modifyselfImpl(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
request.setCharacterEncoding("gb2312");
String id=request.getParameter("id");
String name=request.getParameter("name");
String jiaoshihao=request.getParameter("username");
String password=request.getParameter("password");
String passwordsec=request.getParameter("passwordsec");
String age=request.getParameter("age");
String sex=request.getParameter("sex");
String title=request.getParameter("title");
String course=request.getParameter("course");
String info = this.test(name, jiaoshihao, password,passwordsec);
if (!info.equals("")) {
request.setAttribute("type", info);
return mapping.findForward("fail");
}
int id1=Integer.parseInt(id);
Teacher t=tservice.findTeacherById(id1);
t.setName(name);
t.setJiaoshihao(jiaoshihao);
t.setPassword(password);
t.setAge(age);
t.setSex(sex);
t.setTitle(title);
t.setCourse(course);
tservice.modifyTeacher(t);
return mapping.findForward("success");
}
public ActionForward scoreMgmt(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
return mapping.findForward("success");
}
public ActionForward addscore(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
int tid=(Integer) request.getSession().getAttribute("tid");
Teacher t=tservice.findTeacherById(tid);
String course=t.getCourse();
Collection<Student> students =tservice.findStudentByCourse(course);
request.setAttribute("students", students);
return mapping.findForward("success");
}
public ActionForward toaddscoreImpl(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
String s=request.getQueryString();
String[]ss=s.split("=");
int id=Integer.parseInt(ss[1]);
Student student=sservice.findStudentById(id);
request.setAttribute("st", student);
return mapping.findForward("success");
}
public ActionForward addscoreImpl(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
request.setCharacterEncoding("gb2312");
String name=request.getParameter("name");
String xuehao=request.getParameter("xuehao");
String course=request.getParameter("course");
String point=request.getParameter("point");
Score score=sservice.queryPointByCourseandXuehao(course, xuehao);
if(score!=null){
String p=score.getPoint();
if(p!=null){
return mapping.findForward("fail");
}
}
Score s=new Score();
s.setCoursename(course);
s.setPoint(point);
s.setStudentname(name);
s.setXuehao(xuehao);
tservice.addscore(s);
Collection<Score> scores=tservice.listscore();
request.setAttribute("scores", scores);
return mapping.findForward("success");
}
public ActionForward modifyscore(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
Collection<Score> scores=tservice.listscore();
request.setAttribute("scores", scores);
return mapping.findForward("success");
}
public ActionForward modifyscores(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
String s=request.getQueryString();
String[] ss=s.split("=");
int id=Integer.parseInt(ss[1]);
Score score=tservice.findScoreById(id);
request.setAttribute("mscore", score);
return mapping.findForward("success");
}
public ActionForward modifyscoreImpl(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
request.setCharacterEncoding("gb2312");
String id=request.getParameter("id");
String studentname=request.getParameter("studentname");
String coursename=request.getParameter("coursename");
String xuehao=request.getParameter("xuehao");
String point=request.getParameter("point");
int id1=Integer.parseInt(id);
Score score=tservice.findScoreById(id1);
score.setCoursename(coursename);
score.setPoint(point);
score.setStudentname(studentname);
score.setXuehao(xuehao);
tservice.modifyscore(score);
Collection<Score> scores=tservice.listscore();
request.setAttribute("scores", scores);
return mapping.findForward("success");
}
public ActionForward queryscore(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
Collection<Score> scores=tservice.listscore();
request.setAttribute("scores", scores);
return mapping.findForward("success");
}
public ActionForward removescore(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
Collection<Score> scores=tservice.listscore();
request.setAttribute("scores", scores);
return mapping.findForward("success");
}
public ActionForward removescoreImpl(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
String s=request.getQueryString();
String[] ss=s.split("=");
int id=Integer.parseInt(ss[1]);
tservice.removescore(id);
Collection<Score> scores=tservice.listscore();
request.setAttribute("scores", scores);
return mapping.findForward("success");
}
public ActionForward listscore(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
Collection<Score> scores=tservice.listscore();
request.setAttribute("scores", scores);
return mapping.findForward("success");
}
public String test(String name, String loginname, String loginpassword,
String passwordsec) {
String info = "";
String reg = "^([a-zA-Z0-9_-]|[0-9_-])+@([a-zA-Z0-9_-]|[0-9_-])+[.](((net)|(com)|(cn))|((com)+[.](cn)))$";
String reg1 = "^[a-zA-Z0-9]{2,12}$";
String reg3 = "^([a-zA-Z0-9]{2,8})|(\\W{2,3})$";
String reg2 = "^[0-9]{8,13}$";
if (lo
- 1
- 2
前往页