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-mappings> <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
error.jsp核心代码
<body>
This a struts page. <br><html:errors/>
</body>就这些了,谢谢了
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-mappings> <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
error.jsp核心代码
<body>
This a struts page. <br><html:errors/>
</body>就这些了,谢谢了
Struts1没Struts2好用啊!
这句是干嘛的啊、???return mapping.findForward("success");
这样返回到成功页吧
<forward name="error" path="/error.jsp" />
forward= mapping.findForward("error");
}else{
request.setAttribute("use", regeditForm);
forward= mapping.findForward("ok");
能返回到正确页面吗???你在ction里打一下信息的值,应该也得不到吧
现在可以返回到正确的页面了,可是如果输入的是非admin还是在error.jsp里不显示错误信息的
This a struts page. <br/><html:errors/>
</body>
你好象没有输入错误信息吧。
在<html:errors>我是这样显示的<bean:write name="message" /></html:errors>你在正确页面能得到name: ${use.name }pass:${use.pass }值吗?