问题描述
packagelee;importcom.opensymphony.xwork2.Action;importcom.opensymphony.xwork2.ActionContext;importjava.util.Map;publicclassLoginActionimplementsAction{privateStringusername;privateStringpassword;publicvoidsetUsername(Stringusername){this.username=username;}publicStringgetUsername(){returnthis.username;}publicvoidsetPassword(Stringpassword){this.password=password;}publicStringgetPassword(){returnthis.password;}publicStringexecute()throwsException{ActionContextctx=ActionContext.getContext();//通过ActionContext访问application范围的属性值Integercounter=(Integer)ctx.getApplication().get("counter");if(counter==null){counter=1;}else{counter=counter+1;}//通过ActionContext设置application范围的属性ctx.getApplication().put("counter",counter);//通过ActionContext设置session范围的属性ctx.getSession().put("user",getUsername());if(getUsername().equals("scott")&&getPassword().equals("tiger")){//通过ActionContext设置request范围的属性ctx.put("tip","服务器提示:您已经成功的登陆");returnSUCCESS;}else{//通过ActionContext设置request范围的属性ctx.put("tip","服务器提示:登陆失败");returnERROR;}}}