日期:2014-05-18  浏览次数:20669 次

我写了一个用户登录,但有些地方不知道该怎么写语法,请帮忙看看好吗?
我写了一个用户登录,但有些地方不知道该怎么写语法,请帮忙看看好吗?
我想要如果验证成功就到成功的页面,如果不成功就到失败页面.
public   ActionForward   login(ActionMapping   mapping,
                                                                ActionForm   form,
                                                                HttpServletRequest   req,
                                                                HttpServletResponse   res)   {
              XsBean   bean   =   new   XsBean();
              int   flag;
              try   {
                  String   id   =   req.getParameter( "id ");//用户名
                  String   mm   =   req.getParameter( "mm ");//密码
                  flag=bean.checkUser(id,   mm);
                  if   (flag   ==   1)   {
                      req.getSession().setAttribute( "userName ",   id);
                      String   a   =   (String)   req.getSession().getAttribute( "userName ");
                      System.out.println( "a   is   : "   +   a);
                  }
                  else
                  {
//这里要怎么写
                  }
              }
              catch   (Exception   e)   {
                  e.printStackTrace();
              }
                return   mapping.findForward( "login ");
          }

------解决方案--------------------
if (flag == 1) {
req.getSession().setAttribute( "userName ", id);
String a = (String) req.getSession().getAttribute( "userName ");
System.out.println( "a is : " + a);
return mapping.findForward( "login ");
}
else
{
return mapping.findForward( "fail ");
}

------解决方案--------------------
看来楼主是很新的手啊,我给你解

public ActionForward login(ActionMapping mapping,
ActionForm form,
HttpServletReques