?? registeraction.java
字號:
package com.demo.struts.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionErrors;
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.actions.DispatchAction;
import com.demo.struts.forms.RegisterForm;
import com.demo.struts.util.Constants;
public class RegisterAction extends DispatchAction {
public ActionForward init(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ActionForward forward = mapping.findForward(Constants.FAILURE_KEY);
return (forward);
}
public ActionForward register(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ActionErrors errors = new ActionErrors();
ActionForward forward = new ActionForward();
RegisterForm loginForm = (RegisterForm) form;
try {
String username = loginForm.getUsername();
String password1 = loginForm.getPassword1();
String password2 = loginForm.getPassword2();
String email = loginForm.getEmail();
boolean isRegister = false;
if(username.equals("admin")){
isRegister = true;
}
if(!isRegister){
errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage(
"register.error.failed"));
}
} catch (Exception e) {
errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage(
"register.error.failed"));
}
if (!errors.isEmpty()) {
saveErrors(request, errors);
forward = mapping.findForward(Constants.FAILURE_KEY);
} else {
forward = mapping.findForward(Constants.SUCCESS_KEY);
}
return (forward);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -