ITeye博客

action 返回执行js

lolocomee · 2010-03-29 11:48 · action · 非技术 · HTML · Apache · Markdown

//LoginAction的提交处理函数: public String post() throws Exception{ request = ServletActionContext.getRequest(); session=request.getSession(); String code=(String)session.getAttribute("code"); if(!getCheckcode().equals(code)){ outJs("验证码错误!","login_form.do"); return null; } int i=0; if("".equals(user.getUsername())||"".equals(user.getPassword())){ outJs("用户名密码不能为空!","login_form.do"); fw= null; }else{ i=new UserDao().checkUser(user.getPassword(), user.getUsername()); if(i==0){ outJs("用户名或密码错误,请确认后再填!","login_form.do"); fw= null; }else{ user=new UserDao().getUser(i); new Auth().save(user); if(user.getPri()==1){ fw= "admin"; }else{ fw= "user"; } } } return fw; } //输出信息的js并跳转: private void outJs(String msg,String forword){ ActionContext ctx=ActionContext.getContext(); HttpServletResponse response=(HttpServletResponse)ctx.get(org.apache.struts2.StrutsStatics.HTTP_RESPONSE); response.setContentType("text/html; charset=utf-8"); PrintWriter out=null; try { String str=""; out.print(str); out.close(); } catch (IOException e) { e.printStackTrace(); } }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。