package struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
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 DAO.Cha;
import struts.form.LoginForm;
import struts.form.RegisterForm;
import DAO.DB;
public class RegisterAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
RegisterForm rf=(RegisterForm)form;
Cha cha= new Cha();
if(rf.getId()=="" ||rf.getName()=="" ||rf.getAcademy()=="" ||rf.getPwd()==""|| !rf.getPwd().equalsIgnoreCase(rf.getRepwd()))
{ ActionMessages errors=new ActionMessages();
errors.add("register",new ActionMessage("register.info"));
saveErrors(request,errors);
return mapping.findForward("self");
}
else{
String look="insert into users values ('" + cha.toChinese(rf.getId()) +"','" + cha.toChinese(rf.getMark()) +"','" + cha.toChinese(rf.getName())+ "','" + cha.toChinese(rf.getPwd()) + "','" + cha.toChinese(rf.getEmail())+"','"+cha.toChinese(rf.getTel())+"','"+cha.toChinese(rf.getProfile())+"','"+cha.toChinese(rf.getPost())+"','"+cha.toChinese(rf.getSex())+"','"+cha.toChinese(rf.getAcademy())+ "')";
DB db=new DB();
db.update(look);
LoginForm lf=new LoginForm();
lf.setId(cha.toChinese(rf.getId()));
lf.setMark(cha.toChinese(rf.getMark()));
lf.setPwd(cha.toChinese(rf.getPwd()));
HttpSession hd=request.getSession();
hd.setAttribute("loginform", lf);
hd.setAttribute("name",cha.toChinese(rf.getName()));
hd.setAttribute("id",cha.toChinese(rf.getId()));
hd.setAttribute("tel",cha.toChinese(rf.getTel()));
hd.setAttribute("academy", cha.toChinese(rf.getAcademy()));
hd.setAttribute("post", cha.toChinese(rf.getPost()));
hd.setAttribute("pwd",cha.toChinese(rf.getPwd()));
hd.setAttribute("email", cha.toChinese(rf.getEmail()));
hd.setAttribute("profile", cha.toChinese(rf.getProfile()));
hd.setAttribute("mark", cha.toChinese(rf.getMark()));
if(rf.getMark().equalsIgnoreCase("1"))
return mapping.findForward("student");
else
return mapping.findForward("teacher");
}
}
}
- 1
- 2
前往页