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

为什么,为什么,一个小小的问题困扰了我一天,麻烦前辈帮帮我,我不想说跪求,因为我是男人,所以不会轻易下跪
struts   入门级....现在我想做的是:从regedit.jsp页面上输入用户名和密码,如果两次密码一样,则进入欢迎页面,如果两次密码不一样,提示错误,如果用户名为非admin,则提示用户用户名不能为非admin,可是我做了一天也不对,麻烦前辈指点一下.
regedit.jsp核心代码:
<html:form   action= "/regedit ">
pass1   :   <html:password   property= "pass1 "/> <html:errors   property= "pass1 "/> <br/>
pass   :   <html:password   property= "pass "/> <html:errors   property= "pass "/> <br/>
name   :   <html:text   property= "name "/> <html:errors   property= "name "/> <br/> <html:errors   property= "notname "/>
<html:submit   value= "azafvgafadfs "/> <html:cancel/> <br>
错误信息为: <html:errors/>
</html:form>


成功面ok.jsp核心代码:
    <body>
        welcome   come!   <br>
    name:   ${use.name   }pass:${use.pass   }
    </body>

regeditAction核心代码
public   ActionForward   execute(ActionMapping   mapping,   ActionForm   form,
HttpServletRequest   request,   HttpServletResponse   response)   {
RegeditForm   regeditForm   =   (RegeditForm)   form;//   TODO   Auto-generated   method   stub
ActionForward   forward   =new     ActionForward();

ActionMessages   message   =   null;
if(!regeditForm.getName().equalsIgnoreCase( "admin ")){
message=new   ActionMessages();
  message.add( "notname ",   new   ActionMessage( "regedit.name.not "));
  saveMessages(request,   message);
  forward=   mapping.findForward( "error ");
}else{
request.setAttribute( "use ",   regeditForm);
forward=   mapping.findForward( "ok ");
}

return   forward;
}
struts-config.xml代码:
  <form-beans   >
        <form-bean   name= "regeditForm "   type= "com.yourcompany.struts.form.RegeditForm "   />

    </form-beans>

    <global-exceptions   />
    <global-forwards   />
    <action-mappings   >
        <action
            attribute= "regeditForm "
            input= "/regedit.jsp "
            name= "regeditForm "
            path= "/regedit "
            scope= "request "
            type= "com.yourcompany.struts.action.RegeditAction "   >
            <forward   name= "success "   path= "/ok.jsp "   />
            <forward   name= "error "   path= "/error.jsp "   />
        </action>


    </action-mapping