loginaction.java

来自「一个初学者的入门ssh应用。。。应该对很多人有帮助」· Java 代码 · 共 51 行

JAVA
51
字号
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package org.langsin.web.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 org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.langsin.service.IUserService;
import org.langsin.web.struts.form.LoginForm;

/** 
 * MyEclipse Struts
 * Creation date: 05-20-2007
 * 
 * XDoclet definition:
 * @struts.action path="/login" name="loginForm" input="/login.jsp" scope="request" validate="true"
 */
public class LoginAction extends Action {
private IUserService userService;
	public IUserService getUserService() {
	return userService;
}
public void setUserService(IUserService userService) {
	this.userService = userService;
}
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
		String userName=loginForm.getUsername();
		String userPwd=loginForm.getPassword();
		if(userService.verify(userName, userPwd)){
			request.getSession().setAttribute("user", userName);
			return mapping.findForward("main");
		}else{
			ActionMessages errors=new ActionMessages();
			ActionMessage error=new ActionMessage("error.wrong");
			errors.add("wrong",error);
			this.saveErrors(request, errors);
			return mapping.getInputForward();
		}
		
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?