loginaction.java
来自「基于JAVA的一个注册系统 最初只是为了公司做演示使用」· Java 代码 · 共 67 行
JAVA
67 行
package registerapp;
import org.apache.struts.action.*;
import javax.servlet.http.*;
/*
* @author ye fei
* @version 1.00, 2003/04/15
* @copyright www.studyjava.com
*/
public class LoginAction extends Action {
public ActionForward perform(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
LoginForm rf = (LoginForm) actionForm;
String username = rf.getUsername();
String password1 = rf.getPassword1();
/**
* Validate the request parameters specified by the user
*/
ActionErrors errors = new ActionErrors();
try {
/**
* New UserDirectory object created.
*/
UserDirectory UserDir=new UserDirectory();
/**
* Check the admin.
* if it's an admin then forward to adminmanager.jsp
*/
if (UserDir.isAdmin(username,password1))
return actionMapping.findForward("Admin");
/**
* Check the user.
* if user exist and password is correct
* then forward to success.html
*/
if (!UserDir.isValidPassword(username,password1))
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("error.password.mismatch"));
} catch (UserDirectoryException e) {
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("error.password.mismatch"));
}
/**
* Check the errors.
* if errors is empty then resume and continue.
* else forward to this jsp again and print the errors
*/
if (!errors.empty()) {
saveErrors(httpServletRequest, errors);
return (new ActionForward(actionMapping.getInput()));
}
/**
* Check the user.
* if user exist and password is correct
* then forward to success.html
*/
return actionMapping.findForward("success");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?