RegistAction.java
上传用户:jishiqi_cj
上传日期:2022-08-08
资源大小:24765k
文件大小:2k
- package classmate;
- 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.ActionMessages;
- import org.apache.struts.action.ActionMessage;
- import org.apache.struts.validator.DynaValidatorForm;
- import javax.servlet.ServletContext;
- import javax.sql.DataSource;
- import javax.servlet.http.*;
- public final class RegistAction extends Action{
- public ActionForward execute(
- ActionMapping mapping,
- ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) throws Exception {
-
-
- DynaValidatorForm dyform = (DynaValidatorForm) form;
- String name = (String)dyform.get("name");
- String psw1 = (String)dyform.get("psw1");
- String psw2 = (String)dyform.get("psw2");
-
- ServletContext context = servlet.getServletContext();
- DataSource dataSource = (DataSource)context.getAttribute("oracleDB1");
-
- DBUser dbuser = new DBUser(dataSource);
- HttpSession session = request.getSession();
-
- if (dbuser.Insert(name,psw1)!=0) {
- return (mapping.findForward("registSuccessed"));//注册成功
- }
- else{
- ActionMessages errors = new ActionMessages();
- errors.add(ActionMessages.GLOBAL_MESSAGE,
- new ActionMessage("label.registError"));
-
- if (!errors.isEmpty()) {
- saveErrors(request, errors);
- }
- return mapping.findForward("failed"); //注册失败
- }
- }
- }