login.jsp<form action="login.do" method="post">USER NAME : <input size="15" name="name"><p>
PASSWORD  : <input type="password" size="15" name="psw"><p><input type="submit" value="Login">
</form><a href="regist.jsp">Regist</a>
right.jsp
<%
UserForm userFormBean = (UserForm)request.getAttribute("userFormBean");
if (userFormBean != null && userFormBean.getName() != null) {
%><h1>
Welcome <%=userFormBean.getName()%> !<%
} else {
%>We don't welcome stranger !<%}%>
</h1><br><a href="login.jsp">Login</a>||
<a href="regist.do">Regist</a>

解决方案 »

  1.   

    regist.jsp<form action="regist.do" method="post">USER NAME : <input size="15" name="name"><p>
    PASSWORD  : <input type="password" size="15" name="psw"><p>
    CONFIRM PASSWORD  : <input type="password" size="15" name="cofirmPsw"><p>
    <input type="submit" value="Regist">
    </form><a href="login.jsp">Back to Login Page</a>
    registsuc.jsp
    <%
    RegistForm registFormBean = (RegistForm)request.getAttribute("registFormBean");
    if (registFormBean != null && registFormBean.getName() != null) {
    %>
    <h1>
    Regist successed !<br>
    Welcome <%=registFormBean.getName()%> !
    <%} else {%>
    Regist failed ! Try again !
    <%}%>
    </h1><br><a href="regist.jsp">Regist</a>||
    <a href="login.jsp">login</a>
      

  2.   

    LoginAction.javapublic class LoginAction extends Action { public ActionForward execute(ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) { UserForm userForm = (UserForm) form;
    String name = userForm.getName();
    String psw = userForm.getPsw();

    if(name.equalsIgnoreCase("jenny") && psw.equalsIgnoreCase("hi")) {
    UserLoginLog ul = new UserLoginLog();
    ul.save(name, psw);
    return mapping.findForward("loginsuccessed");
    } else {
    return mapping.findForward("loginfailed");
    }

    }
    }
    UserForm.java
    public class UserForm extends ActionForm { private String name = null;
    private String psw = null;

    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public String getPsw() {
    return psw;
    }
    public void setPsw(String psw) {
    this.psw = psw;
    }


    }
      

  3.   

    RegistAction.javapublic class RegistAction extends Action { public ActionForward execute(ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) {

    RegistForm registForm = (RegistForm) form;
    String psw = registForm.getPsw();
    String confirmPsw = registForm.getCofirmPsw();

    if (psw.equalsIgnoreCase(confirmPsw)) {
                                //**********************************
                                //注意这一句,不加在registsuc.jsp就取不到registFormBean,
                                //为什么???? 但是那个login的例子里就没有这个阿?
    request.setAttribute("registFormBean", registForm);
                                 //***************************************
    return mapping.findForward("registsuccessed");
    } else {
    return mapping.findForward("registfailed");
    }

    }

    }RegistForm.java
    public class RegistForm extends ActionForm { private String name = null;
    private String psw =null;
    private String cofirmPsw = null;

    public String getCofirmPsw() {
    return cofirmPsw;
    }
    public void setCofirmPsw(String cofirmPsw) {
    this.cofirmPsw = cofirmPsw;
    }
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public String getPsw() {
    return psw;
    }
    public void setPsw(String psw) {
    this.psw = psw;
    }


    }
      

  4.   

    六楼代码中间有问题                            //**********************************
                                //注意这一句,不加在registsuc.jsp就取不到registFormBean,
                                //为什么???? 但是那个login的例子里就没有这个阿?
    request.setAttribute("registFormBean", registForm);
                                 //***************************************
    return mapping.findForward("registsuccessed");
      

  5.   

    Login那个业务的代码是书上的例子
    没有任何问题我仿照那个做了个注册的regist业务
    其他的都正常
    就是在成功后跳转到的页面取不到前页应该传过来的数据
    是一个对象,即RegistForm得实例(Login那个是UserForm)
      

  6.   

    RegistForm registForm = (RegistForm) form;
    String psw = registForm.getPsw();
    String confirmPsw = registForm.getCofirmPsw();把psw,confirmPsw打出来看看结果~~~看看这两个字符串是什么~~~System.out.println("psw = "+psw+" confirmPsw = " + confirmPsw);
      

  7.   

    在java文件里利用Debug追踪的时候都是正确的
    也能跳转到成功页(registsuc.jsp)
    但是在registsuc.jsp中 registFormBean == null 这个判断结果是true
      

  8.   

    <action path="/regist" type="users.RegistAction" name="registFormBean" scop="request" input="regist.jsp"/>里的input页是表单验证失败返回的页,当然不能取到值了~~~~
    这么些试试
    <action path="/regist" type="users.RegistAction" name="registFormBean" scop="request">
    <forward id="registsuccessed" path="regist.jsp"/>
    </action>
    学习框架要搞清楚它的原理和流程~~~
      

  9.   

    先谢谢一直关注为什么Login这么些就能取到呢?
    <action path="/login" type="users.LoginAction" name="userFormBean" scope="request" input="login.jsp"/>
      

  10.   

    request.setAttribute("registFormBean", registForm);你确定这句执行了么?
      

  11.   

    或者你把registsuc.jsp里的
    <%
    RegistForm registFormBean = (RegistForm)request.getAttribute("registFormBean");
    if (registFormBean != null && registFormBean.getName() != null) {
    %>
    <h1>
    Regist successed !<br>
    Welcome <%=registFormBean.getName()%> !
    <%} else {%>
    Regist failed ! Try again !
    <%}%>这段换成 ${registFormBean.name}试试
      

  12.   

    <action path="/regist" type="users.RegistAction" name="registFormBean" scop="request" input="regist.jsp"/>总算明白你的意思了,你的代码是直接粘贴过来的么??scop写错了,应该是scope,找疯了,细心点啊