Struts2 文件上传下载

上传人:简****9 文档编号:109720691 上传时间:2019-10-27 格式:DOC 页数:30 大小:1.37MB
返回 下载 相关 举报
Struts2 文件上传下载_第1页
第1页 / 共30页
Struts2 文件上传下载_第2页
第2页 / 共30页
Struts2 文件上传下载_第3页
第3页 / 共30页
Struts2 文件上传下载_第4页
第4页 / 共30页
Struts2 文件上传下载_第5页
第5页 / 共30页
点击查看更多>>
资源描述

《Struts2 文件上传下载》由会员分享,可在线阅读,更多相关《Struts2 文件上传下载(30页珍藏版)》请在金锄头文库上搜索。

1、具体步骤: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类,此类要继承Ac

2、tionSupport类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(S

3、tring 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文件

4、,在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(

5、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(两次输入

6、的密码不一致!);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

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 管理学资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号