资源预览内容
第1页 / 共30页
第2页 / 共30页
第3页 / 共30页
第4页 / 共30页
第5页 / 共30页
第6页 / 共30页
第7页 / 共30页
第8页 / 共30页
第9页 / 共30页
第10页 / 共30页
亲,该文档总共30页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
具体步骤:1.新建web项目 命名为struts2demo2.向工程中导入所需要的jar包 必要的jar包有七个3.在web.xml文件中注册struts2struts2org.apache.struts2.dispatcher.FilterDispatcher struts2/*4.编写输入邀请码的JSP页面invite.jsp 验证码校验 请输入您的验证码: 5.在Tomcat的server.xml中加入工程 6.启动Tomcat服务器 测试当前所做是否有错误以上表明当前设置没有错误!7.在src下新建com.demo.action包,并在其中新建InviteAction类,此类要继承ActionSupport类package com.demo.action;import java.util.Map;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;public class InviteAction extends ActionSupport private String invitedcode;public String getInvitedcode() return invitedcode;public void setInvitedcode(String invitedcode) this.invitedcode = invitedcode;Overridepublic String execute() throws Exception if(220081078.equals(this.getInvitedcode() return SUCCESS;elsethis.addFieldError(invitedcode, 输入的邀请码不正确!请再次输入!);return INPUT;类中规定只有输入的验证码为220081078,才能进入到注册页面,否则会出现错误的提示信息并回到原页面继续输入。8.在src下新建struts.xml文件,在struts.xml文件中对InviteAction进行注册 /invite.jsp/register.jsp 9.新建register.jsp页面,并加入如下代码注册页面function validate()var usernameValue = document.getElementById(usernameId).value;var passwordValue = document.getElementById(passwordId).value;var repasswordValue = document.getElementById(repasswordId).value;if(usernameValue.length = 0)alert(用户名不能为空!);return false;else if(usernameValue.length 16)alert(用户名只能由6-16位字母和数字组成!);return false;if(passwordValue.length = 0)alert(密码不能为空!);return false;else if(passwordValue.length 16)alert(用户名只能由6-16位字母和数字组成!);return false;if(passwordValue != repasswordValue)alert(两次输入的密码不一致!);return false;return true;*用户名: *密码: *重复密码: 年龄: 生日: 其中脚本validate()方法对输入进行客户端的验证,如果没有输入必填项(用户名和密码)或输入的长度超过限制,都会提示相应的错误信息。10.对以上所做工作进行测试 如果输入错误的邀请码 如2200810888 则显示结果如下如果输入正确的邀请码 如220081078 则转入到注册页面 测试成功!11.在action包中创建RegisterAction类 并编写如下代码package com.demo.action;import java.util.Calendar;import java.util.Date;import com.opensymphony.xwork2.ActionSupport;public class RegisterAction extends ActionSupport private String username;private String password;private String repassword;private int age;private Date
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号