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>就这些了,谢谢了
解决方案 »
- 有关类型转换问题
- 求高人指点如何使用Jtree实现树,并支持节点拖拽
- 关于属小母牛的问题 改了一下cow.grow();的位置,结果咋就不一样了啊 ,想不明白啊 (从网上找的一个例子)
- 编写一个 Java GUI 编程实现队列数据结构操作演示器 (原码)
- JAVA自带的有哪些package,每个package又包括哪些class,每个class又有哪些method
- 给树图节点设置icon的问题
- 为什么没人理我的问题?就因为我给的分低吗?你们这些高手也太见钱眼开了吧
- 同样的程序为什么在ACCESS可以运行而在SQL Server不能运行?
- 我是JAVA新人,几个问题请教!!!
- java菜鸟求助
- 这样的java反射,怎么实现
- return this
错误信息显示不出来: 其他的错误信息有这个问题吗?是不是没有对应上呀?bean信息显示不出来:不知道会不会是生存周期的问题?Page? 试一下在execute有没有取到值?
知道你的意思,看着你的代码也不太懂,我这有登陆验证的代码,发给你一份要吗?
你的action不是很规范,或我只会用考来的这个方式呵
application.properties文件写什么没?
这里的命名错了,在Action里面forward= mapping.findForward("ok");转向的时候应该是forward= mapping.findForward("success");你再仔细看看,估计不是什么大问题。