userloginaction.java
来自「MyEclipse6Java中文教程的代码」· Java 代码 · 共 38 行
JAVA
38 行
package com.yourcompany.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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 com.yourcompany.struts.form.UserLoginForm;
/**
* 登录验证功能。
* 作者:BeanSoft
*
* XDoclet definition:
*
* @struts.action path="/userLogin" name="userLoginForm" input="/userLogin.jsp"
* scope="request" validate="true"
* @struts.action-forward name="failed" path="/userLogin.jsp"
* @struts.action-forward name="success" path="/userLoginSuccess.jsp"
*/
public class UserLoginAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UserLoginForm userLoginForm = (UserLoginForm) form;// TODO
// Auto-generated
// method stub
if (userLoginForm.getUserName().equals("myeclipse")
&& userLoginForm.getPassword().equals("myeclipse")) {
// 用户登录的一般做法是把信息放入session(会话)中
request.getSession(true).setAttribute("loginedUser", userLoginForm);
return mapping.findForward("success");
}
return mapping.findForward("failed");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?