📄 loginaction.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -